N, K = map(int, input().split())

k = (N - 1) * (N - 2) // 2

if k < K:
  print(-1)
  exit()
  
answer = []
for i in range(2, N+1):
  answer.append([1, i])
# print(answer)

for i in range(2, N+1):
  for j in range(i+1, N+1):
    if k == K:
      print(len(answer))
      for a in answer:
        print(*a)
      exit()
    else:
      k -= 1
      answer.append([i, j])
print(len(answer))
for a in answer:
  print(*a)
exit() N, K = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split K k = (N - 1) * (N - 2) // 2 k (N - 1) * (N - 2) // 2 (N - 1) * (N - 2) N - 1 N 1 N - 2 N 2 2 if k < K:
  print(-1)
  exit()
   k < K k K print(-1) print -1 exit() exit answer = [] answer [] for i in range(2, N+1):
  answer.append([1, i])
# print(answer) i range(2, N+1) range 2 N+1 N 1 answer.append([1, i]) answer.append answer append [1, i] 1 i for i in range(2, N+1):
  for j in range(i+1, N+1):
    if k == K:
      print(len(answer))
      for a in answer:
        print(*a)
      exit()
    else:
      k -= 1
      answer.append([i, j]) i range(2, N+1) range 2 N+1 N 1 for j in range(i+1, N+1):
    if k == K:
      print(len(answer))
      for a in answer:
        print(*a)
      exit()
    else:
      k -= 1
      answer.append([i, j]) j range(i+1, N+1) range i+1 i 1 N+1 N 1 if k == K:
      print(len(answer))
      for a in answer:
        print(*a)
      exit()
    else:
      k -= 1
      answer.append([i, j]) k == K k K print(len(answer)) print len(answer) len answer for a in answer:
        print(*a)
       a answer print(*a) print *a a exit() exit k -= 1 k 1 answer.append([i, j]) answer.append answer append [i, j] i j print(len(answer)) print len(answer) len answer for a in answer:
  print(*a) a answer print(*a) print *a a exit() exit N, K = map(int, input().split()) map(int, input().split()) N answer = [] [] answer K = map(int, input().split()) map(int, input().split()) K k = (N - 1) * (N - 2) // 2 (N - 1) * (N - 2) // 2 k k -= 1 1 k
N, K = map(int, input().split())

k = (N - 1) * (N - 2) // 2

if k < K:
  print(-1)
  exit()
  
answer = []
for i in range(2, N+1):
  answer.append([1, i])
# print(answer)

for i in range(2, N+1):
  for j in range(i+1, N+1):
    if k == K:
      print(len(answer))
      for a in answer:
        print(*a)
      exit()
    else:
      k -= 1
      answer.append([i, j])
print(len(answer))
for a in answer:
  print(*a)
exit()