import sys
from collections import deque

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


INF = 10 * 5


def warshall_floyd(V, cost):
    for k in range(V):
        for i in range(V):
            for j in range(V):
                if cost[i][k] != INF and cost[k][j] != INF:
                    cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])


def main():

    N, K = in_nn()

    G = [[INF] * N for _ in range(N)]
    ans = []

    for i in range(1, N):
        G[0][i] = 1
        G[i][0] = 1
        ans.append((1, i + 1))

    warshall_floyd(N, G)

    comb = []
    for i in range(N):
        for j in range(i + 1, N):
            if G[i][j] == 2:
                comb.append((i + 1, j + 1))

    comb = deque(comb)
    max_k = len(comb)

    if max_k < K:
        print(-1)
        exit()

    while max_k > K:
        max_k -= 1
        ans.append(comb.popleft())

    print(len(ans))
    for i, j in ans:
        print(i, j)


if __name__ == '__main__':
    main() import sys sys from collections import deque read = sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline readlines = sys.stdin.buffer.readlines readlines sys.stdin.buffer.readlines sys.stdin.buffer sys.stdin sys stdin buffer readlines in_n = lambda: int(readline()) in_n lambda: int(readline()) int(readline()) int readline() readline in_nn = lambda: map(int, readline().split()) in_nn lambda: map(int, readline().split()) map(int, readline().split()) map int readline().split() ().split () readline split in_s = lambda: readline().rstrip().decode('utf-8') in_s lambda: readline().rstrip().decode('utf-8') readline().rstrip().decode('utf-8') ().rstrip().decode ().rstrip() ().rstrip () readline rstrip decode 'utf-8' in_nl = lambda: list(map(int, readline().split())) in_nl lambda: list(map(int, readline().split())) list(map(int, readline().split())) list map(int, readline().split()) map int readline().split() ().split () readline split in_nl() for _ in range(H) for _ in range(H) _ range(H) range H for _ in range(H) in_nl() in_nl in_nl2 = lambda H: [in_nl() for _ in range(H)] in_nl2 lambda H: [in_nl() for _ in range(H)] [in_nl() for _ in range(H)] H s == ord('.') for s in readline() if s != ord('\n') for s in readline() if s != ord('\n') s readline() readline s != ord('\n') s ord('\n') ord '\n' if s != ord('\n') s == ord('.') s ord('.') ord '.' in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')] in_map lambda: [s == ord('.') for s in readline() if s != ord('\n')] [s == ord('.') for s in readline() if s != ord('\n')] in_map() for _ in range(H) for _ in range(H) _ range(H) range H for _ in range(H) in_map() in_map in_map2 = lambda H: [in_map() for _ in range(H)] in_map2 lambda H: [in_map() for _ in range(H)] [in_map() for _ in range(H)] H in_all = lambda: map(int, read().split()) in_all lambda: map(int, read().split()) map(int, read().split()) map int read().split() ().split () read split INF = 10 * 5 INF 10 * 5 10 5 def warshall_floyd(V, cost):
    for k in range(V):
        for i in range(V):
            for j in range(V):
                if cost[i][k] != INF and cost[k][j] != INF:
                    cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]) warshall_floyd for k in range(V):
        for i in range(V):
            for j in range(V):
                if cost[i][k] != INF and cost[k][j] != INF:
                    cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]) k range(V) range V for i in range(V):
            for j in range(V):
                if cost[i][k] != INF and cost[k][j] != INF:
                    cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]) i range(V) range V for j in range(V):
                if cost[i][k] != INF and cost[k][j] != INF:
                    cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]) j range(V) range V if cost[i][k] != INF and cost[k][j] != INF:
                    cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]) cost[i][k] != INF and cost[k][j] != INF cost[i][k] != INF cost[i][k] [i] cost i k INF cost[k][j] != INF cost[k][j] [k] cost k j INF cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]) cost[i][j] [i] cost i j min(cost[i][j], cost[i][k] + cost[k][j]) min cost[i][j] [i] cost i j cost[i][k] + cost[k][j] cost[i][k] [i] cost i k cost[k][j] [k] cost k j V V cost cost def main():

    N, K = in_nn()

    G = [[INF] * N for _ in range(N)]
    ans = []

    for i in range(1, N):
        G[0][i] = 1
        G[i][0] = 1
        ans.append((1, i + 1))

    warshall_floyd(N, G)

    comb = []
    for i in range(N):
        for j in range(i + 1, N):
            if G[i][j] == 2:
                comb.append((i + 1, j + 1))

    comb = deque(comb)
    max_k = len(comb)

    if max_k < K:
        print(-1)
        exit()

    while max_k > K:
        max_k -= 1
        ans.append(comb.popleft())

    print(len(ans))
    for i, j in ans:
        print(i, j) main N, K = in_nn() N in_nn() in_nn K [INF] * N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [INF] * N [INF] INF N G = [[INF] * N for _ in range(N)] G [[INF] * N for _ in range(N)] ans = [] ans [] for i in range(1, N):
        G[0][i] = 1
        G[i][0] = 1
        ans.append((1, i + 1))

     i range(1, N) range 1 N G[0][i] = 1 G[0][i] [0] G 0 i 1 G[i][0] = 1 G[i][0] [i] G i 0 1 ans.append((1, i + 1)) ans.append ans append (1, i + 1) 1 i + 1 i 1 warshall_floyd(N, G) warshall_floyd N G comb = [] comb [] for i in range(N):
        for j in range(i + 1, N):
            if G[i][j] == 2:
                comb.append((i + 1, j + 1))

     i range(N) range N for j in range(i + 1, N):
            if G[i][j] == 2:
                comb.append((i + 1, j + 1))

     j range(i + 1, N) range i + 1 i 1 N if G[i][j] == 2:
                comb.append((i + 1, j + 1))

     G[i][j] == 2 G[i][j] [i] G i j 2 comb.append((i + 1, j + 1)) comb.append comb append (i + 1, j + 1) i + 1 i 1 j + 1 j 1 comb = deque(comb) comb deque(comb) deque comb max_k = len(comb) max_k len(comb) len comb if max_k < K:
        print(-1)
        exit()

     max_k < K max_k K print(-1) print -1 exit() exit while max_k > K:
        max_k -= 1
        ans.append(comb.popleft())

     max_k > K max_k K max_k -= 1 max_k 1 ans.append(comb.popleft()) ans.append ans append comb.popleft() comb.popleft comb popleft print(len(ans)) print len(ans) len ans for i, j in ans:
        print(i, j) i j ans print(i, j) print i j if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():

    N, K = in_nn()

    G = [[INF] * N for _ in range(N)]
    ans = []

    for i in range(1, N):
        G[0][i] = 1
        G[i][0] = 1
        ans.append((1, i + 1))

    warshall_floyd(N, G)

    comb = []
    for i in range(N):
        for j in range(i + 1, N):
            if G[i][j] == 2:
                comb.append((i + 1, j + 1))

    comb = deque(comb)
    max_k = len(comb)

    if max_k < K:
        print(-1)
        exit()

    while max_k > K:
        max_k -= 1
        ans.append(comb.popleft())

    print(len(ans))
    for i, j in ans:
        print(i, j) def main():

    N, K = in_nn()

    G = [[INF] * N for _ in range(N)]
    ans = []

    for i in range(1, N):
        G[0][i] = 1
        G[i][0] = 1
        ans.append((1, i + 1))

    warshall_floyd(N, G)

    comb = []
    for i in range(N):
        for j in range(i + 1, N):
            if G[i][j] == 2:
                comb.append((i + 1, j + 1))

    comb = deque(comb)
    max_k = len(comb)

    if max_k < K:
        print(-1)
        exit()

    while max_k > K:
        max_k -= 1
        ans.append(comb.popleft())

    print(len(ans))
    for i, j in ans:
        print(i, j) main readlines = sys.stdin.buffer.readlines sys.stdin.buffer.readlines readlines in_map2 = lambda H: [in_map() for _ in range(H)] lambda H: [in_map() for _ in range(H)] in_map2 in_n = lambda: int(readline()) lambda: int(readline()) in_n in_nl = lambda: list(map(int, readline().split())) lambda: list(map(int, readline().split())) in_nl readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline in_nl2 = lambda H: [in_nl() for _ in range(H)] lambda H: [in_nl() for _ in range(H)] in_nl2 read = sys.stdin.buffer.read sys.stdin.buffer.read read in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')] lambda: [s == ord('.') for s in readline() if s != ord('\n')] in_map in_nn = lambda: map(int, readline().split()) lambda: map(int, readline().split()) in_nn in_all = lambda: map(int, read().split()) lambda: map(int, read().split()) in_all INF = 10 * 5 10 * 5 INF in_s = lambda: readline().rstrip().decode('utf-8') lambda: readline().rstrip().decode('utf-8') in_s def warshall_floyd(V, cost):
    for k in range(V):
        for i in range(V):
            for j in range(V):
                if cost[i][k] != INF and cost[k][j] != INF:
                    cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]) def warshall_floyd(V, cost):
    for k in range(V):
        for i in range(V):
            for j in range(V):
                if cost[i][k] != INF and cost[k][j] != INF:
                    cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]) warshall_floyd
import sys
from collections import deque

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


INF = 10 * 5


def warshall_floyd(V, cost):
    for k in range(V):
        for i in range(V):
            for j in range(V):
                if cost[i][k] != INF and cost[k][j] != INF:
                    cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])


def main():

    N, K = in_nn()

    G = [[INF] * N for _ in range(N)]
    ans = []

    for i in range(1, N):
        G[0][i] = 1
        G[i][0] = 1
        ans.append((1, i + 1))

    warshall_floyd(N, G)

    comb = []
    for i in range(N):
        for j in range(i + 1, N):
            if G[i][j] == 2:
                comb.append((i + 1, j + 1))

    comb = deque(comb)
    max_k = len(comb)

    if max_k < K:
        print(-1)
        exit()

    while max_k > K:
        max_k -= 1
        ans.append(comb.popleft())

    print(len(ans))
    for i, j in ans:
        print(i, j)


if __name__ == '__main__':
    main()
