Buggy python submission (verdict: Runtime Error):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()

limit = sum(range(1, N-1))

if K > limit:  # むり
	print(-1)
else:  # いける
	edge = list(combinations(range(1, N+1),2))
	index = 0
	for i in range(K):
		if edge[i][1] == N:
			index += 1
		else:
			edge.pop(index)

	print(N*(N-1)//2 - K)
	for u, v in edge:
		print(u, v)


Fixed submission:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()

limit = sum(range(1, N-1))

if K > limit:  # むり
	print(-1)
else:  # いける
	edge = list(combinations(range(1, N+1),2))
	if K == 0:
		print(N*(N-1)//2)
		for u, v in edge:
			print(u, v)
	else:	
		rem = []
		count = 0
		for i in edge:
			if i[1] != N:
				rem.append(i)
				count += 1
				if count == K:
					break
		for i in rem:
			edge.remove(i)

		print(N*(N-1)//2 - K)
		for u, v in edge:
			print(u, v)

Buggy python submission (verdict: Runtime Error):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()

limit = sum(range(1, N-1))

# print(list(combinations(range(1, N+1),2)))
if K > limit:  # むり
	print(-1)
else:  # いける
	edge = list(combinations(range(1, N+1),2))
	for i in range(K):
		if edge[i][1] == N:
			continue
		else:
			edge.pop(0)

	print(N*(N-1)//2 - K)
	for u, v in edge:
		print(u, v)


Fixed submission:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()

limit = sum(range(1, N-1))

if K > limit:  # むり
	print(-1)
else:  # いける
	edge = list(combinations(range(1, N+1),2))
	if K == 0:
		print(N*(N-1)//2)
		for u, v in edge:
			print(u, v)
	else:	
		rem = []
		count = 0
		for i in edge:
			if i[1] != N:
				rem.append(i)
				count += 1
				if count == K:
					break
		for i in rem:
			edge.remove(i)

		print(N*(N-1)//2 - K)
		for u, v in edge:
			print(u, v)

Buggy python submission (verdict: Runtime Error):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()

limit = sum(range(1, N-1))
if K > limit:  # むり
	print(-1)
else:  # いける
	edge = list(combinations(range(1, N+1),2))
	for i in range(K):
		if edge[i][1] == N:
			continue
		else:
			edge.pop(0)

	print(N*(N-1)//2 - K)
	for i in edge:
		print(i)


Fixed submission:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()

limit = sum(range(1, N-1))

if K > limit:  # むり
	print(-1)
else:  # いける
	edge = list(combinations(range(1, N+1),2))
	if K == 0:
		print(N*(N-1)//2)
		for u, v in edge:
			print(u, v)
	else:	
		rem = []
		count = 0
		for i in edge:
			if i[1] != N:
				rem.append(i)
				count += 1
				if count == K:
					break
		for i in rem:
			edge.remove(i)

		print(N*(N-1)//2 - K)
		for u, v in edge:
			print(u, v)

Buggy python submission (verdict: Runtime Error):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()

limit = sum(range(1, N-1))
if K > limit:  # むり
	print(-1)
else:  # いける
	edge = list(combinations([1,2,3,4,5],2))
	for i in range(K):
		if edge[i][1] == N:
			continue
		else:
			edge.pop(0)

	print(N*(N-1)//2 - K)
	for i in edge:
		print(i)


Fixed submission:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()

limit = sum(range(1, N-1))

if K > limit:  # むり
	print(-1)
else:  # いける
	edge = list(combinations(range(1, N+1),2))
	if K == 0:
		print(N*(N-1)//2)
		for u, v in edge:
			print(u, v)
	else:	
		rem = []
		count = 0
		for i in edge:
			if i[1] != N:
				rem.append(i)
				count += 1
				if count == K:
					break
		for i in rem:
			edge.remove(i)

		print(N*(N-1)//2 - K)
		for u, v in edge:
			print(u, v)