var
 fin,fout:textfile;
 map:array[0..101000] of longint;
 n,m,i,k:longint;
 b:boolean;
begin
 assignfile(fin,'irrelevant.in');
 assignfile(fout,'irrelevant.out');
 reset(fin);
 rewrite(fout);
 readln(fin,n,m);
 map[0]:=0;
 map[1]:=1;
 for i:=2 to n do begin
  map[i]:=1;
  for k:=i-1 downto 1 do begin
   map[k]:=(map[k]+map[k-1]) mod m;
  end;
 end;
 k:=0;
 for i:=1 to n do
  if map[i]=0 then k:=k+1;
 writeln(fout,k);
 b:=true;
 for i:=1 to n do
  if map[i]=0 then begin
   if not b then begin
    write(fout,' ');
   end else begin
    b:=false;
   end;
   write(fout,i);
  end;
 writeln(fout,'');
 closefile(fin);
 closefile(fout);
end.