n, k = map(int, input().split()) if n > 2 * k: print(-1) exit() ANS = [] for i in range(1, n - k + 1): p = 2 * i - 1 q = 2 * i ANS.append((p, p)) ANS.append((p, q)) ANS.append((q, p)) for i in range(2 * (n - k) + 1, n + 1): ANS.append((i, i)) print(len(ANS)) for x, y in ANS: print(x, y)