program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var fin,fout:text;
    a,b:array[1..100000] of integer;
    k,j,i:integer;
    s:array[1..100000] of integer;
    n,m,sum,count:integer;
begin
   assign(fin,'irrelevant.in');
   assign(fout,'irrelavant.out');
   reset(fin);rewrite(fout);
   readln(fin,n,m);
   randomize;
   for i:=1 to n do a[i]:=i mod m;
   b:=a;
   for k:=n-1 downto 1 do
   for j:=1 to n do
   a[j]:=(a[j+1]+a[j]) mod m;
   sum:=a[1];
   count:=0;

   for i:=1 to n do
   begin
   a:=b; a[i]:=0;
   for k:=n-1 downto 1 do
     for j:=1 to n do
        a[j]:=(a[j+1]+a[j]) mod m;
   if a[1]=sum then
      begin
        count:=count+1;
        s[count]:=i;
      end;
   end;
   writeln(fout,count);
   for i:=1 to count do write(fout,s[i],' ');
   close(fin);close(fout);
end.
