program i;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  F : Text;
  C, i1, j, k, l, p : Integer;
  a : Array [1..100000] of int64;
  B : Array [1..50000] of Integer;
  N : Integer;
  m : Integer;
  Flag, prFlag : Boolean;
begin

  Assign(F, 'irrelevant.in');
  Reset(F);
  Read(F, n);
  Read(F, M);
  Close(F);
  C := 0;

  for i1 := 1 to N do begin
    for j := 1 to N do
      a[j] := 0;

    a[i1] := 1;
    k := N-1;

    while (k > 0) do begin
      for j := 1 to k do begin
        A[j] := A[j] + A[Succ(j)];
      end;
      Dec(k);
    end;

    if A[1] mod m = 0 then begin
      Inc(C);
      B[C] := i1;
    end;


  end;

  Assign(F, 'irrelevant.out');

  ReWrite(F);
  if C > 0 then begin
    Writeln(F, C);
    For i1 := 1 to C - 1 do begin
      Write(F, B[i1], ' ');
    end;
    Write(F, B[C]);
  end else Write(F, '0');
  Close(F);
end.
