program i1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  n,m,k,i,j: integer;
  a,b: array[1..200000] of integer;

begin
  AssignFile(Input,'irrelevant.in'); Reset(Input);
  ReadLn(n,m);
  CloseFile(Input);
  a[1] := 1;
  for i := 2 to 200000 do a[i] := 0;
  for i := 1 to n do
  begin
    b[1] := 1;
    for j := 2 to i do
      b[j] := (a[j-1]+a[j]) mod m;
    for j := 1 to i do
      a[j] := b[j];
  end;
  k := 0;
  for i := 1 to n do
    if a[i]=0 then
    begin
      inc(k);
      b[k] := i;
    end;
  AssignFile(Output,'irrelevant.out'); Rewrite(Output);
  writeln(k);
  if k>0 then write(b[1]);
  for i := 2 to k do write(' ',b[i]);
  CloseFile(Output);


end.
