{
    ACM ICPC 2003-2004 NEERC

    Problem:    Game
    Author:     Andrew Stankevich
    Solution:   Maxim Babenko
}

{$APPTYPE CONSOLE}

const
    inFile = 'game.in';
    outFile = 'game.out';

    maxN = 200;
    maxM = 100;

var
    n, m : integer;
    w : array[1..maxN,1..maxN] of boolean;
    cnt : array[1..maxN*maxN] of integer;

procedure Solve;
var
    i, j, k : integer;

begin
    for i := 1 to n do
        for j := i + 1 to n do
            w[i,j] := true;

    for i := 1 to m + 1 do
        if odd(i) then begin
            fillchar(cnt, sizeof(integer) * n * 2, 0);

            for j := 1 to n do
                for k := j + 1 to n do
                    if w[j,k] then
                        inc(cnt[j+k]);

            for j := 1 to n do
                for k := j + 1 to n do
                    if w[j,k] and ((cnt[j+k] = 1) xor (i = m + 1)) then
                        w[j,k] := false;
        end else begin
            fillchar(cnt, sizeof(integer) * n * n, 0);

            for j := 1 to n do
                for k := j + 1 to n do
                    if w[j,k] then
                        inc(cnt[j*k]);

            for j := 1 to n do
                for k := j + 1 to n do
                    if w[j,k] and ((cnt[j * k] = 1) xor (i = m + 1)) then
                        w[j,k] := false;
        end;
end;

procedure ReadData;
begin
    read(n, m);
    if (n < 2) or (n > maxN) then
        RunError(239);
    if (m < 0) or (m > maxM) then
        RunError(239);
end;

procedure WriteData;
var
    i, j, cnt : integer;

begin
    cnt := 0;
    for i := 1 to n do
        for j := 1 to n do
            if w[i,j] then
                inc(cnt);

    writeln(cnt);
    for i := 1 to n do
        for j := 1 to n do
            if w[i,j] then
                writeln(i, ' ', j);
end;

begin
    ReadData;
    Solve;
    WriteData;
end.
