program Task_I;

{$APPTYPE CONSOLE}

type
  BigInt = record
    N: array[1..20] of Int64;
    Len: Integer;
  end;

var
  N, M, Count, i: Integer;
  Mas: array[1..100000] of Boolean;
  R: Int64;
  R1, R2, R3: BigInt;

procedure AssignBigInt(var N1: BigInt; N2: BigInt);
var
  i: Integer;
begin
  N1.Len := N2.Len;
  for i := 1 to 20 do
    N1.N[i] := N2.N[i];
end;

procedure AssignInt(var N1: BigInt; N2: Integer);
var
  i: Integer;
begin
  for i := 1 to 20 do
    N1.N[i] := 0;
  N1.Len := 1;
  N1.N[1] := N2 mod 1000000000;
end;

procedure Mul(N1, N2: BigInt; var N3: BigInt);
var
  i, j: Integer;
  LP, P: Int64;
begin
  for i := 1 to N1.Len + N2.Len do
    N3.N[i] := 0;
  for i := 1 to N1.Len do
    begin
      P := 0;
      for j := 1 to N2.Len do
        begin
          LP := P;
          P := (N3.N[i + j - 1] + N1.N[i] * N2.N[j] + P) div 1000000000;
          N3.N[i + j - 1] := (N3.N[i + j - 1] + N1.N[i] * N2.N[j] + LP) mod 1000000000;
        end;
      N3.N[i + N2.Len] := P;
    end;
  i := 20;
  while (i > 1) and (N3.N[i] = 0) do
    Dec(i);
  N3.Len := i;
end;

procedure DivInt(R1: BigInt; Del: Int64; var Res: BigInt);
var
  i: Integer;
  T: Int64;
  TBig: BigInt;
begin
  i := R1.Len;
  TBig.Len := 0;
  T := 0;
  while i > 0 do
    begin
      T := T * 1000000000 + R1.N[i];
      if T = 0 then
        begin
          Inc(TBig.Len);
          TBig.N[TBig.Len] := T div Del;
          T := T mod Del;
        end
      else
        if T >= Del then
          begin
            Inc(TBig.Len);
            TBig.N[TBig.Len] := T div Del;
            T := T mod Del;
          end;
      Dec(i);
    end;
  Res.Len := TBig.Len;
  for i := 1 to 20 do
    Res.N[i] := 0;
  for i := 1 to TBig.Len do
    Res.N[TBig.Len - i + 1] := TBig.N[i];
end;

procedure ModInt(R1: BigInt; Del: Int64; var Ost: Int64);
var
  i: Integer;
  T: Int64;
begin
  i := R1.Len;
  T := 0;
  while i > 0 do
    begin
      T := T * 1000000000 + R1.N[i];
      T := T mod Del;
      Dec(i);
    end;
  Ost := T;  
end;

begin
  Assign(input, 'irrelevant.in');
  Reset(input);
  Assign(output, 'irrelevant.out');
  ReWrite(output);
  ReadLn(N, M);
  for i := 1 to N do
    Mas[i] := False;
  Count := 0;
  AssignInt(R1, 1);
  R := 1;
  for i := 1 to N - 1 do
    begin
      if R = 0 then
        begin
          Mas[i] := True;
          Inc(Count);
        end;
      AssignInt(R2, N - i);
      Mul(R1, R2, R3);
      AssignBigInt(R1, R3);
      DivInt(R1, i, R3);
      AssignBigInt(R1, R3);
      ModInt(R1, M, R);
    end;
  WriteLn(Count);
  for i := 1 to N do
    if Mas[i] then
      Write(i, ' ');
end.

