{$A+,B-,C+,D+,E-,F-,G+,H+,I+,J-,K-,L+,M-,N+,O-,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y+,Z1}
uses Math;
type
    tans = array [0..10000] of boolean;
    int128 = array [0..100] of int64;
var
   n,m : integer;
   ans : tans;

Procedure Init;
Begin
   fillchar(ans,sizeof(ans),false);
   read(n,m);
   n := n -1 ;
End;

function Get128(x : int64) : Int128;
begin
   fillchar(Result,sizeof(Result),0);
   while x > 0 do begin
      inc(Result[0]);
      Result[Result[0]] := x mod 10;
      x := x div 10;
   end;
end;

function More(x,y : int128) : boolean;
var
   i : integer;
begin
   If x[0] > y[0] then begin
      Result := true;
      exit;
   end;
   i := x[0];
   while i > 0 do begin
      if x[i] > y[i] then begin
         Result := true;
         exit;
      end else
         if x[i] < y[i] then begin
            Result := false;
            exit;
         end;
      dec(i);
   end;
   Result := false;
end;

function MoreEq(x,y : int128) : boolean;
var
   i : integer;
begin
   If x[0] > y[0] then begin
      Result := true;
      exit;
   end;
   i := x[0];
   while i > 0 do begin
      if x[i] > y[i] then begin
         Result := true;
         exit;
      end else
         if x[i] < y[i] then begin
            Result := false;
            exit;
         end;
      dec(i);
   end;
   Result := True;
end;

function Mn(a,b : int128) : int128;
var
   i : integer;
   c : integer;
begin
   fillchar(Result,sizeof(Result),0);
   If MoreEq(a,b) then begin
      c := 0;
      for i := 1 to a[0] do
         Result[i] := a[i] - b[i];
      i := 1;
      while (i < b[0])or(c>0) do begin
         Result[i] := Result[i] -c;
         if Result[i] < 0 then begin
            c := 1;
            Result[i] := 10+Result[i];
         end else
            c := 0;
      end;
      Result[0] := a[0];
      while (Result[Result[0]]= 0) and (Result[0] > 0) do
         dec(Result[0]);
   end else
      Result := Get128(0);
end;

function Mult(a : int128; b : integer) : int128;
var
  i : integer;
begin
   fillchar(Result,sizeof(Result),0);
   for i := 1 to a[0] do
      Result[i] := a[i]*b;
   for i := 1 to a[0] do begin
      Result[i + 1] := Result[i+1] + Result[i] div 10;
      Result[i] := result[i] mod 10;
   end;
   i := a[0];
   while Result[i] > 0 do begin
      Result[i + 1] := Result[i+1] + Result[i] div 10;
      Result[i] := result[i] mod 10;
      inc(i);
   end;
   dec(i);
   Result[0] := Max(i,0);
end;

function Dv(a : int128;b : integer) : int128;
var
   p,i : integer;
   c : int64;
begin
   fillchar(Result,sizeof(Result),0);
   c := 0;
   for i := a[0] downto 1 do begin
      c := c*10 + a[i];
      Result[i] := c div b;
      c := c mod b;
   end;
   for i := 1 to a[0] div 2 do begin
      p := Result[i];
      Result[i] := Result[a[0]-i+1];
      Result[a[0]-i+1] := p;
   end;
   i := 1;
   while (Result[i] > 0)or(i <= a[0]) do begin
      Result[i + 1] := Result[i+1] + Result[i] div 10;
      Result[i] := result[i] mod 10;
      inc(i);
   end;
   while (Result[i] = 0) and(i > 0) do
      dec(i);
   Result[0] := i;
end;

function Md(a : int128;b : integer) : integer;
var
   t : int128;
begin
   t := Dv(a,b);
   t := Mn(a,Mult(t,b));
   Result := t[1]; 
end;

function GCD(a,b: integer) : integer;
begin
   while (a > 1) and (b > 1) do begin
      a := a - (a div b)*b;
      if a = 0 then begin
         Result := b;
         exit;
      end;
      b := b - (b div a)*a;
      if b = 0 then begin
         Result := a;
         exit;
      end;
   end;
   Result := 	1;
end;

function GetMD(a,m:integer) : integer;
begin
   Result := 1;
   while GCD(a,m) > 1 do begin
      Result := Result * GCD(a,m);
      a := a div GCD(a,m);
   end;
end;

Procedure Solve;
var
   k : integer;
   c : int128;
   a,b : integer;
   step : integer;
Begin
   c := Get128(1);
   step := 0;
   for k := 1 to n do begin
      a := GetMD(n-k+1,m);
      b := GetMD(k,m);
      c := Mult(c,a);
{      while Md(c,b) <> 0 do begin
         dec(step);
         c := Mult(c,m);
      end;}
      c := Dv(c,b);
{      while Md(c,m) = 0 do begin
         c := Dv(c,m);
         inc(step);
      end;}
      if Md(c,m)=0 then
         ans[k+1] := true;
   end;
End;

Procedure Save;
var
   cnt,i : integer;
Begin
   cnt := 0;
   for i := 1 to n do
      if ans[i] then
         inc(cnt);
   writeln(cnt);
   for i := 1 to n do
      if ans[i] then  begin
         write(i,' ');
      end;
End;

begin
assign(input,'irrelevant.in'); reset(input);
assign(output,'irrelevant.out'); rewrite(output);
  Init;
  Solve;
  Save;
close(input);
close(output);
end.
