var
   P            :array[1..120000]of longint;
   n,i,num      :longint;
   m            :longint;
   sum          :longint;
procedure readfile;
begin
   assign(input,'irrelevant.in');
   assign(output,'irrelevant.out');
   reset(input);
   rewrite(output);
   read(n,m);
end;
begin
   readfile;
      num:=1;
      P[1]:=1;
      P[n]:=1;
     if n mod 2 = 0 then
     begin
      for i:=1 to (n div 2) do
      begin
         num:=((num*(n-i))div i) mod m;
         P[i+1]:=num;
         P[n-i]:=num;
      end;

     end else
     begin
      for i:=1 to ((n div 2)) do
      begin
         num:=((num*(n-i))div i) mod m;
         P[i+1]:=num;
         if i<>((n div 2)+1)then
         P[n-i]:=num;
      end;
     end;
{     for i:=1 to n do
     begin
     write(P[i],' ');
     end;}
      sum:=0;
      p[1]:=p[1] mod m;
      p[n]:=p[n] mod m;
      for i:=1 to n do
      begin
         if P[i]=0 then inc(sum);
      end;
      writeln(sum);
      for i:=1 to n do
      begin
         if P[i]=0 then write(i,' ');
      end;
   close(input);
   close(output);
end.
