Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
L = []
R = []
count = 0
for j in range(M):
  l,r = map(int,input().split())
  L.append(l)
  R.append(r)
for i in range(N+1):
  if i >= max(L) and i <= min(R):
    count += 1
print(count)

Fixed submission:
N,M = map(int,input().split())
L = []
R = []
ans = 0
for _ in range(M):
  l, r = map(int, input().split())
  L.append(l)
  R.append(r)
ans = max(0,min(R) - max(L) + 1)
print(ans)

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
L = []
R = []
count = 0
for j in range(M):
  L,R = map(int,input().split())
for i in range(N+1):
  if i > max(L) and i < min(R):
    count += 1

Fixed submission:
N,M = map(int,input().split())
L = []
R = []
ans = 0
for _ in range(M):
  l, r = map(int, input().split())
  L.append(l)
  R.append(r)
ans = max(0,min(R) - max(L) + 1)
print(ans)

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
L,R = list(map(int,input().split()))
count = 0
for i in range(N+1):
  if i > max(L) and i < min(R):
    count += 1

Fixed submission:
N,M = map(int,input().split())
L = []
R = []
ans = 0
for _ in range(M):
  l, r = map(int, input().split())
  L.append(l)
  R.append(r)
ans = max(0,min(R) - max(L) + 1)
print(ans)

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
L,R = [list(map(int,input().split())) for _ in range(M)]
count = 0
for i in range(N+1):
  if i > max(L) and i < min(R):
    count += 1
print(count)

Fixed submission:
N,M = map(int,input().split())
L = []
R = []
ans = 0
for _ in range(M):
  l, r = map(int, input().split())
  L.append(l)
  R.append(r)
ans = max(0,min(R) - max(L) + 1)
print(ans)

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
L = list(map(int,input().split()))
R = list(map(int,input().split()))
ans = 0
if N >= min(R):
  ans = max(0,min(R) - min(L) + 1)
else:
  ans = max(0,N - min(L) + 1)
print(ans)


Fixed submission:
N,M = map(int,input().split())
L = []
R = []
ans = 0
for _ in range(M):
  l, r = map(int, input().split())
  L.append(l)
  R.append(r)
ans = max(0,min(R) - max(L) + 1)
print(ans)

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
L = [list(map(int,input().split())) for _ in range(M)]
R = [list(map(int,input().split())) for _ in range(M)]
L.sort()
R.sort()
count = 0
for i in range(1,N+1):
  if i >= L[-1] and i <= R[0]:
    count += 1
print(count)

Fixed submission:
N,M = map(int,input().split())
L = []
R = []
ans = 0
for _ in range(M):
  l, r = map(int, input().split())
  L.append(l)
  R.append(r)
ans = max(0,min(R) - max(L) + 1)
print(ans)

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
L = list(map(int,input().split()))
R = list(map(int,input().split()))
L.sort()
R.sort()
count = 0
for i in range(1,N+1):
  if i >= L[-1] and i <= R[0]:
    count += 1
print(count)

Fixed submission:
N,M = map(int,input().split())
L = []
R = []
ans = 0
for _ in range(M):
  l, r = map(int, input().split())
  L.append(l)
  R.append(r)
ans = max(0,min(R) - max(L) + 1)
print(ans)

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
L = list(map(int,input().split()))
R = list(map(int,input().split()))
L.sort()
R.sort()
count = 0
for i in range(N):
  if i >= L[0] and i <= R[0]:
    count += 1
print(count)

Fixed submission:
N,M = map(int,input().split())
L = []
R = []
ans = 0
for _ in range(M):
  l, r = map(int, input().split())
  L.append(l)
  R.append(r)
ans = max(0,min(R) - max(L) + 1)
print(ans)

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
LR = [list(map(int,input().split())) for _ in range(N)]
count = 0
for i in range(N):
  for j,k in LR:
    if i >= j and i <= k:
      count += 1
print(count)


Fixed submission:
N,M = map(int,input().split())
L = []
R = []
ans = 0
for _ in range(M):
  l, r = map(int, input().split())
  L.append(l)
  R.append(r)
ans = max(0,min(R) - max(L) + 1)
print(ans)