N, K = gets.split.map(&:to_i)
if N == 2 || (K > N - 2)
  puts "-1"
  exit(0)
end
ans = []
t = 0
ans << [1, 2]
i = 3
while t < K
  ans << [2, i]
  ((i + 1)..(K + 2)).each do |j|
    ans << [i, j]
  end
  t += 1
  i += 1
end
(i..N).each do |j|
  (1..N).each do |k|
    break if j == k
    ans << [j, k]
  end
end
puts ans.size
ans.each do |e|
  puts "#{e[0]} #{e[1]}"
end
