program irrelevant;

var
  I, N, M, K, L: 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
      Writeln(1);
      Writeln('2 ');
    end
      else
  begin
    K := N - 1;
    L := 1;
    for I := 2 to N - 2 do
      Inc(L, I);
    if K mod M = 0 then K := -1;
    if (N >= 5) and (L mod M = 0) then L := -1;
    if (K < 0) and (L < 0) then
    begin
      Writeln(N - 2);
      Write(2);
      for I := 3 to N - 2 do Write(' ', I);
      Writeln(' ', N - 1);
    end
      else
      if K < 0 then
      begin
        Writeln(2);
        Writeln('2 ', N - 1);
      end
        else
        if L < 0 then
        begin
          Writeln(N - 4);
          for I := 3 to N - 2 do
            Write(I, ' ');
          Writeln;
        end
          else Writeln(0);
  end;
end.
