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

left, right = map(int, input().split())
ans = set(range(left, right+1))
               
for i in range(m-1):
  left, right = map(int, input().split())
  set_temp = set(range(left, right+1))
  ans = ans & set_temp
print(len(ans))

Fixed submission:
n, m = map(int, input().split())
min_num = 0
max_num = 10**5
           
for i in range(m):
  min_temp, max_temp = map(int, input().split())
  if min_temp > min_num:
    min_num = min_temp
  if max_temp < max_num:
    max_num = max_temp
print(max(max_num - min_num + 1, 0))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
list_open = []
for i in range(m):
  list_open.append(list((int(i) for i in input().split())))
dict_open = {}
for i in range(m):
  for j in range(list_open[i][0], list_open[i][1] + 1):
    try:
      dict_open[j] += 1
      if dict_open[j] < i:
        del dict_open[j]
    except:
      if i == 0:
      	dict_open[j] = 1
print(list(dict_open.values()).count(m))

Fixed submission:
n, m = map(int, input().split())
min_num = 0
max_num = 10**5
           
for i in range(m):
  min_temp, max_temp = map(int, input().split())
  if min_temp > min_num:
    min_num = min_temp
  if max_temp < max_num:
    max_num = max_temp
print(max(max_num - min_num + 1, 0))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
list_open = []
for i in range(m):
  list_open.append(list((int(i) for i in input().split())))
dict_open = {}
for i in range(m):
  for j in range(list_open[i][0], list_open[i][1] + 1):
    try:
      dict_open[j] += 1
    except:
      dict_open[j] = 1
print(list(dict_open.values()).count(m))

Fixed submission:
n, m = map(int, input().split())
min_num = 0
max_num = 10**5
           
for i in range(m):
  min_temp, max_temp = map(int, input().split())
  if min_temp > min_num:
    min_num = min_temp
  if max_temp < max_num:
    max_num = max_temp
print(max(max_num - min_num + 1, 0))

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
list_open = []
for i in range(m):
  list_open.append(list((int(i) for i in input().split())))
dict_open = {}
for i in range(m):
  for j in range(list_open[i][0], list_open[i][1] + 1):
    try:
      dict_open[j] += 1
    else:
      dict_open[j] = 1
print(list(dict_open.values()).count(m))

Fixed submission:
n, m = map(int, input().split())
min_num = 0
max_num = 10**5
           
for i in range(m):
  min_temp, max_temp = map(int, input().split())
  if min_temp > min_num:
    min_num = min_temp
  if max_temp < max_num:
    max_num = max_temp
print(max(max_num - min_num + 1, 0))

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
list_open = []
for i in range(m):
  list_open.append(list((int(i) for i in input().split())))
dict_open = {}
for i in range(m):
  for j in range(list_open[i][0], list_open[i][1] + 1):
    try:
      dict_open[j] += 1
    else:
      dict_open[j] = 1
print(list(dict_open.values()).count(m)

Fixed submission:
n, m = map(int, input().split())
min_num = 0
max_num = 10**5
           
for i in range(m):
  min_temp, max_temp = map(int, input().split())
  if min_temp > min_num:
    min_num = min_temp
  if max_temp < max_num:
    max_num = max_temp
print(max(max_num - min_num + 1, 0))