program Project1;
 {$APPTYPE CONSOLE}
 Var
   n: integer;
   m: int64;
   ans: array [0..100000] of integer;
 Procedure Load;
 Begin
   assign(input, 'irrelevant.in');
   reset(input);
   readln(n, m);
   close(input);
 End;
{-------------------------------------------------------------------------}

function binom(k: int64): int64;
var
  i: integer;
  s: int64;
begin
  s := 1;
  if k < n - 1 - k then begin
    for i := n - k to n - 1 do
      s := s * i div (i - n + k + 1);
  end
  else begin
    for i := k + 1 to n - 1 do
      s := s * i div (i - k);
  end;
  binom := s;
end;

 Procedure Solve;
var
  coef: integer;
  i: integer;
 Begin
   for i := 1 to n do begin
     coef := binom(i - 1);
     if coef mod m = 0 then begin
       inc(ans[0]);
       ans[ans[0]] := i;
     end;
   end;
 End;
{-------------------------------------------------------------------------}
 Procedure Save;
 var
   i: integer;
 Begin
   assign(output, 'irrelevant.out');
   rewrite(output);
   writeln(ans[0]);
   for i := 1 to ans[0] do
     write(ans[i], ' ');
   close(output);
 End;
{-------------------------------------------------------------------------}
 BEGIN
  load;
  Solve;
  Save;
 END.
