const maxn=100000;
      readfile='irrelevant.in';
      writefile='irrelevant.out';

Var n,m,kol:longint;
    a,a1:array[0..maxn] of integer;
    b:array[1..maxn] of integer;
{-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-}
Procedure Rfile;
Var i1,j1:longint;
begin
     assign(input,readfile);
     reset(input);
     read(n,m);
     close(input);
end;
{-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-}
pROCEDURE recurs(k:integer);
var i1,j1:integer;
begin
     if k mod 2=0 then
     begin
          for i1:=1 to k do
              a1[i1]:=(a[i1]+a[i1-1])mod m;
     end
     else
     begin
          for i1:=1 to k do
              a[i1]:=(a1[i1]+a1[i1-1])mod m;
     end;
end;
{-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-}
Procedure Main;
var i1,j1,zz:longint;
begin
     a[1]:=1;
     for i1:=2 to n do
         recurs(i1);
     if n mod 2=0 then
     begin
          for i1:=1 to n do
              if a1[i1]=0 then
              begin
                   inc(kol);
                   b[kol]:=i1;
              end;
          end
     else
     begin
          for i1:=1 to n do
              if a[i1]=0 then
              begin
                   inc(kol);
                   b[kol]:=i1;
              end;
     end;
end;
{-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-}
Procedure Wfile;
var i1,j1:integer;
begin
     assign(output,writefile);
     rewrite(output);
     writeln(kol);
     for i1:=1 to kol do
         write(b[i1],' ');
     close(output);
end;
{-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-}
begin
     Rfile;
     Main;
     Wfile;
end.