uses
  SysUtils;

var m1:array[0..100000,1..2]of integer;
    n,m,cur,i,num:integer;

procedure genNext;
var j: integer; 
begin
  for j:=1 to i+1 do
    m1[j,cur]:=(m1[j,3-cur]+m1[j-1,3-cur])mod m;
  cur:=3-cur;
end;

begin
  assignfile(input, 'irrelevant.in');
  assignfile(output, 'irrelevant.out');
  reset(input);
  rewrite(output);

  readln(n,m);
  cur:=1;
  fillchar(m1,sizeof(m1),0);
  m1[1,2]:=1;
  for i:=1 to n-1 do
    gennext;

  cur:=3-cur;
  num:=0;
  for i:=1 to n do
    if m1[i,cur]=0
    then inc(num);
  writeln(num);
  for i:=1 to n do
    if m1[i,cur]=0
    then write(i,' ');

  closefile(input);
  closefile(output);
end.
