program irrelevant;

var
  Count, I, J, N, M, K, L: Integer;
  A: array of Integer;

begin
  Assign(Input, 'irrelevant.in');
  Assign(Output, 'irrelevant.out');
  Read(N, M);
  if N <= 2 then Writeln(0) else
    if N = 3 then
    begin
      if M = 2 then
      begin
        Writeln(1);
        Writeln('2 ');
      end
        else Writeln(0);
    end
      else
  begin
/////////////////////
    SetLength(A, N + 1);
    A[1] := 1;
    for I := 2 to (N + 1) div 2 do
    begin
      A[I] := A[I - 1];
      for J := I downto 2 do A[J] := (A[J] + A[J - 1]) mod M;
      if not Odd(N) or (I <> (N + 1) div 2) then
        for J := I downto 2 do A[J] := (A[J] + A[J - 1]) mod M;
    end;
    for I := 1 to N div 2 do A[N - I + 1] := A[I];
    Count := 0;
    for I := 1 to N do
      if A[I] = 0 then Inc(Count);
    Writeln(Count);
    for I := 1 to N do
      if A[I] = 0 then Write(I, ' ');
    Writeln;
/////////////////////
  end;
end.
