Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
card = set(list(range(1, N+1)))
for _ in range(M):
  l, r = map(int, input().split())
  gate = set(list(range(l, r+1)))
  card &= gate
print(len(card))

Fixed submission:
card, gate = map(int, input().split())
max_l = 0
min_r = 100000
for i in range(gate):
  l, r = map(int, input().split())
  max_l = max(max_l, l)
  min_r = min(min_r, r)
print(len(range(max_l, min_r+1)))

Buggy python submission (verdict: Runtime Error):
card, gate = map(int, input().split())
l, r = map(int, input().split())
ans = {i for i in range(l, r+1)}
for i in range(gate-1):
  l, r = map(int, input().split())
  if l > min(ans) or max(ans) > r:
    l, r = max(min(ans), l), min(max(ans), r)
    ans = {i for i in range(l, r+1) if i in ans}
print(len(ans))

Fixed submission:
card, gate = map(int, input().split())
max_l = 0
min_r = 100000
for i in range(gate):
  l, r = map(int, input().split())
  max_l = max(max_l, l)
  min_r = min(min_r, r)
print(len(range(max_l, min_r+1)))

Buggy python submission (verdict: Runtime Error):
card, gate = map(int, input().split())
l, r = map(int, input().split())
ans = {i for i in range(l, r+1)}
for i in range(gate-1):
  l, r = map(int, input().split())
  l, r = max(min(ans), l), min(max(ans), r)
  ans = {i for i in range(l, r+1) if i in ans}
print(len(ans))

Fixed submission:
card, gate = map(int, input().split())
max_l = 0
min_r = 100000
for i in range(gate):
  l, r = map(int, input().split())
  max_l = max(max_l, l)
  min_r = min(min_r, r)
print(len(range(max_l, min_r+1)))

Buggy python submission (verdict: Time Limit Exceeded):
card, gate = map(int, input().split())
l, r = map(int, input().split())
ans = {i for i in range(l, r+1)}
for i in range(gate-1):
  l, r = map(int, input().split())
  ans = ans & {i for i in range(l, r+1)}
print(len(ans))

Fixed submission:
card, gate = map(int, input().split())
max_l = 0
min_r = 100000
for i in range(gate):
  l, r = map(int, input().split())
  max_l = max(max_l, l)
  min_r = min(min_r, r)
print(len(range(max_l, min_r+1)))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

card, gate = map(int, input().split())
ans = [i for i in range(1, card+1)]
for i in range(gate):
  l, r = map(int, input().split())
  ans = np.intersect1d(ans, [i for i in range(l, r+1)])
print(len(ans))

Fixed submission:
card, gate = map(int, input().split())
max_l = 0
min_r = 100000
for i in range(gate):
  l, r = map(int, input().split())
  max_l = max(max_l, l)
  min_r = min(min_r, r)
print(len(range(max_l, min_r+1)))

Buggy python submission (verdict: Time Limit Exceeded):
card, gate = map(int, input().split())
ans = {i for i in range(1, card+1)}
for i in range(gate):
  l, r = map(int, input().split())
  ans = ans & {i for i in range(l, r+1)}
print(len(ans))

Fixed submission:
card, gate = map(int, input().split())
max_l = 0
min_r = 100000
for i in range(gate):
  l, r = map(int, input().split())
  max_l = max(max_l, l)
  min_r = min(min_r, r)
print(len(range(max_l, min_r+1)))

Buggy python submission (verdict: Time Limit Exceeded):
card, gate = map(int, input().split())
ans = {i for i in range(1, card+1)}
for i in range(gate):
  l, r = map(int, input().split())
  ans = ans & {i for i in range(l, r+1)}
print(len(ans))

Fixed submission:
card, gate = map(int, input().split())
max_l = 0
min_r = 100000
for i in range(gate):
  l, r = map(int, input().split())
  max_l = max(max_l, l)
  min_r = min(min_r, r)
print(len(range(max_l, min_r+1)))