program irrelevant;
const
 maxn=100002;
type
 tmas=array[0..1,0..maxn+1] of longint;
var
 i,j,k,kk,n,m:longint;
 r:array[1..maxn] of longint;
 a:tmas;
begin
  assign(input,'irrelevant.in');
  reset(input);
  assign(output,'irrelevant.out');
  rewrite(output);
  readln(n,m);
  fillchar(a,sizeof(a),0);
  k:=0;
  a[0,1]:=1;
  for i:=2 to n do
  begin
    for j:=1 to i div 2 do a[1-k,j]:=(a[k,j]+a[k,j-1]) mod m;
    if i mod 2=1 then a[1-k,(i div 2) + 1]:=(a[k,i div 2]*2) mod m;
    k:=1-k;
  end;

  kk:=0;
  for i:=1 to n div 2 do if a[k,i]=0 then
  begin
    inc(kk);
    r[kk]:=i;
  end;

  if n mod 2=1 then if a[k,n div 2 +1]=0 then
  begin
    inc(kk);
    r[kk]:=n div 2 +1;
  end;

  for i:=n div 2 downto 1 do if a[k,i]=0 then
  begin
    inc(kk);
    r[kk]:=n-i+1;
  end;

  writeln(kk);
  for i:=1 to kk do write(r[i],' ');
  close(input);
  close(output);
end.

