Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int,input().split())


def main():
	Ls = []
	Rs = []
	for i in range(M):
		inputs = list(map(int,input().split()))
		Ls.append(inputs[0])
		Rs.append(inputs[1])

	result = set()
	for i in range(1, M + 1):
		Li = Ls[i - 1]
		LiPlus = { j for j in range(Li + 1, Rs[i - 1] + 1) }
		LiPlus.add(Li)

		if len(result) == 0:
			result = LiPlus
			continue
		result = result & LiPlus

	print(len(result))

if __name__ == '__main__':
	main()

Fixed submission:
N, M = map(int,input().split())


def main():
	Ls = []
	Rs = []
	for i in range(M):
		inputs = list(map(int,input().split()))
		Ls.append(inputs[0])
		Rs.append(inputs[1])

	maxL = max(Ls)
	minR = min(Rs)

	if maxL > minR:
		print(0)
	else:
		print(minR - maxL + 1)

if __name__ == '__main__':
	main()

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int,input().split())


def main():
	Ls = []
	Rs = []
	for i in range(M):
		inputs = list(map(int,input().split()))
		Ls.append(inputs[0])
		Rs.append(inputs[1])

	result = set()
	for i in range(1, M + 1):
		Li = Ls[i - 1]
		LiPlus = [j for j in range(Li + 1, Rs[i - 1] + 1)]
		if len(result) == 0:
			result = set([Li] + LiPlus)
			continue
		result = result & set([Li] + LiPlus)

	print(len(result))

if __name__ == '__main__':
	main()

Fixed submission:
N, M = map(int,input().split())


def main():
	Ls = []
	Rs = []
	for i in range(M):
		inputs = list(map(int,input().split()))
		Ls.append(inputs[0])
		Rs.append(inputs[1])

	maxL = max(Ls)
	minR = min(Rs)

	if maxL > minR:
		print(0)
	else:
		print(minR - maxL + 1)

if __name__ == '__main__':
	main()

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int,input().split())


def main():
	Ls = []
	Rs = []
	for i in range(M):
		inputs = list(map(int,input().split()))
		Ls.append(inputs[0])
		Rs.append(inputs[1])

	result = set()
	for i in range(1, M + 1):
		Li = Ls[i - 1]
		LiPlus = [j for j in range(Li + 1, Rs[i - 1] + 1)]
		if len(result) == 0:
			result = set([Li] + LiPlus)
		result = result & set([Li] + LiPlus)

	print(len(result))

if __name__ == '__main__':
	main()

Fixed submission:
N, M = map(int,input().split())


def main():
	Ls = []
	Rs = []
	for i in range(M):
		inputs = list(map(int,input().split()))
		Ls.append(inputs[0])
		Rs.append(inputs[1])

	maxL = max(Ls)
	minR = min(Rs)

	if maxL > minR:
		print(0)
	else:
		print(minR - maxL + 1)

if __name__ == '__main__':
	main()

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int,input().split())

from collections import defaultdict


def main():
	Ls = []
	cardDic = defaultdict(int)
	Rs = []
	for i in range(M):
		inputs= list(map(int,input().split()))
		Ls.append(inputs[0])
		cardDic[inputs[0]] += 1
		Rs.append(inputs[1])
		cardDic[inputs[1]] += 1

	result = []
	for i in range(1, M + 1):
		Li = Ls[i - 1]
		LiPlusOne = Li + 1
		LiPlus = [j for j in range(Li + 1, Rs[i - 1] + 1)]

		res = set([Li] + LiPlus)

		if len(result) == 0:
			result.extend(list(res))
		result = list(set(result) & res)

	print(len(result))

if __name__ == '__main__':
	main()

Fixed submission:
N, M = map(int,input().split())


def main():
	Ls = []
	Rs = []
	for i in range(M):
		inputs = list(map(int,input().split()))
		Ls.append(inputs[0])
		Rs.append(inputs[1])

	maxL = max(Ls)
	minR = min(Rs)

	if maxL > minR:
		print(0)
	else:
		print(minR - maxL + 1)

if __name__ == '__main__':
	main()

Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())

As = list(map(int,input().split())).sort()

Bs = []
Cs = []
for i in range(M):
	inputs = list(map(int,input().split()))
	Bs.append(inputs[0])
	Cs.append(inputs[1])

for j in range(1, M + 1):
	for n in range(Bs[j - 1]):
		if As[n] < Cs[j - 1]:
			As[n] = Cs[j - 1]
	As.sort()

print(sum(As))

Fixed submission:
N, M = map(int,input().split())


def main():
	Ls = []
	Rs = []
	for i in range(M):
		inputs = list(map(int,input().split()))
		Ls.append(inputs[0])
		Rs.append(inputs[1])

	maxL = max(Ls)
	minR = min(Rs)

	if maxL > minR:
		print(0)
	else:
		print(minR - maxL + 1)

if __name__ == '__main__':
	main()