var
  n, m: longint;
  md: array [1..100000] of longint;
  num, r, i: longint;
  bool: boolean;

begin
  assign(input, 'irrelevant.in');
  assign(output, 'irrelevant.out');
  reset(input);
  rewrite(output);
  readln(n, m);
  n := n - 1;
  num := 0;
  md[1] := 1;
  for i := 2 to (n div 2) + 1 do
  begin
    md[i] := round(md[i - 1] + md[i - 1] * (n - 2 * i - 1) / (i + 1)) mod m;
    if odd(n) then
      md[n - i - 1] := md[i]
    else
      md[n - i] := md[i];
    if md[i] = 0 then
      inc(num);
  end;
  bool := false;
  if not odd(n) then
    writeln(num * 2 - 1)
  else
    writeln(num * 2);  
  for i := 1 to n do
    if md[i] = 0 then
      if not bool then
      begin
        write(i);
        bool := true;
      end
      else
        write(' ', i);
  close(input);
  close(output);
end.
