var a,b:array[0..100010] of longint;
    i,j,k,n,m,p:longint;
    begin
      assign(input,'irrelevant.in');
      reset(input);
      assign(output,'irrelevant.out');
      rewrite(output);
      read(n,m);
      a[1]:=1;
      for j:=1 to n-1 do
        begin
          a[j+1]:=0;
          for i:=j downto 1 do
            a[i+1]:=(a[i]+a[i+1]) mod m;
        end;
      p:=0;
      for i:=1 to n do
        if a[i]=0 then p:=p+1;
      writeln(p);
      for i:=1 to n do
        if a[i]=0 then write(i,' ');
      close(input);
      close(output);
    end.
