uses
  SysUtils;

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

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

procedure genNext5;
var j: integer;
    A: int64;
begin
  for j:=1 to n1+5 do
    begin
      A := m1[j,3-cur] mod m;
      A := (A + (5* int64(m1[j-1,3-cur])) mod m) mod m;
      A := (A + (10*int64(m1[j-2,3-cur])) mod m) mod m;
      A := (A + (10*int64(m1[j-3,3-cur])) mod m) mod m;
      A := (A + (5*int64(m1[j-4,3-cur])) mod m) mod m;
      A := (A + (int64(m1[j-5,3-cur])) mod m) mod m;
      m1[j,cur]:= A;{(m1[j,3-cur]+5*m1[j-1,3-cur]+10*m1[j-2,3-cur]+
        10*m1[j-3,3-cur]+5*m1[j-4,3-cur]+m1[j-5,3-cur])mod m;}
    end;
  cur:=3-cur;
  n1:=n1+5;
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;
  n1:=1;
  while n1+5<=n do
     gennext5;
  while n1+1<=n 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.
