{$APPTYPE CONSOLE}


const
    _fin='irrelevant.in';
    _fout='irrelevant.out';
    MAXN=100001;
    MAXMN=100000;

var cc,i,n,m:longint;
    a:array[0..MAXN] of longint;
    was:boolean;
function nod(a,b:INT64):int64;
begin
    if a=0 then begin
        nod:=1;
        exit;
    end else
    if a<b then begin
        nod:=nod(b,a);
        exit;
    end else
    if a mod b=0 then begin
        nod:=b;
        exit;
    end else nod:=nod(a,a mod b);
end;

function count(a,b:longint):int64;
var t:int64;
    res:int64;
begin
    t:=b;
    res:=0;
    while t<=a do
    begin
        res:=res+(a div t);
        t:=t*b;
    end;
    count:=res;
end;

procedure process;
var j,c,mm,i:longint;
    aa,bb:int64;
    mn:array[1..maxmn,1..2] of longint;
    z:boolean;
begin
    mm:=m;
    cc:=0;
    c:=0;
    a[0]:=1 mod m;
    for i:=2 to trunc(sqrt(m)+1) do
        while mm mod i=0 do
        begin
            if mn[c,1]<>i then begin inc(c);mn[c,1]:=i;mn[c,2]:=0;end;
            inc(mn[c,2]);
            mm:=mm div i;
        end;
    if mm<>1 then begin
        inc(c);
        mn[c,1]:=mm;
        mn[c,2]:=1;
    end;
    for i:=1 to n-1 do
    begin
        z:=true;
        for j:=1 to c do
        begin
            aa:=count(n-1,mn[j,1]);
            bb:=count(i,mn[j,1])+count(n-1-i,mn[j,1]);
            if (aa-bb)<mn[j,2] then z:=false;
        end;
        if z then begin a[i]:=0;inc(cc);end else a[i]:=1;
    end;

end;
begin
    assign(input,_fin);reset(input);
    read(n,m);
    close(input);
    process;
    assign(output,_fout);rewrite(output);
    writeln(cc);
    was:=false;
    for i:=0 to n-1 do
    begin
        if a[i]=0 then begin
          if was then write(' ') else was:=true;

            write(i+1);
        end;
    end;
    writeln;
    close(output);
end.