N, K = map(int, input().split()) if 2 * K < N: print(-1) exit() ans = [] for i in range(K): ans.append((i, i)) for i in range(K, N): ans.append((i, i - K)) ans.append((i - K, i)) print(len(ans)) for a, b in ans: print(a + 1, b + 1)