Buggy python submission (verdict: Time Limit Exceeded):
#ABC 127 C - Prison
from collections import Counter

n, m = map(int, input().split())
gates = []
for i in range(m):
    l, r = map(int, input().split())
    temp_l = range(l-1,r)
    gates.extend(temp_l)

c = Counter(gates)
res = 0
for v in c.values():
    if v == m: res += 1
print(res)

Fixed submission:
n, m = map(int, input().split())
L, R = [], []
for _ in range(m):
    l,r = map(int, input().split())
    L.append(l)
    R.append(r)


res = min(R) - max(L) + 1
if res < 0:
    print(0)
else:
    print(res)

Buggy python submission (verdict: Time Limit Exceeded):
#ABC 127 C - Prison
from collections import Counter

n, m = map(int, input().split())
gates = []
for i in range(m):
    l, r = map(int, input().split())
    for j in range(l-1, r):
        gates.append(j)

c = Counter(gates)
res = 0
for v in c.values():
    if v == m: res += 1
print(res)

Fixed submission:
n, m = map(int, input().split())
L, R = [], []
for _ in range(m):
    l,r = map(int, input().split())
    L.append(l)
    R.append(r)


res = min(R) - max(L) + 1
if res < 0:
    print(0)
else:
    print(res)

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
L, R = [], []
for _ in range(m):
    l,r = map(int, input().split())
    L.append(l)
    R.append(r)


res = min(R) - max(L) + 1
if res < 0:
    print(0)
else:
    print(ans)

Fixed submission:
n, m = map(int, input().split())
L, R = [], []
for _ in range(m):
    l,r = map(int, input().split())
    L.append(l)
    R.append(r)


res = min(R) - max(L) + 1
if res < 0:
    print(0)
else:
    print(res)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
L, R = [], []
for _ in range(m):
    l,r = map(int, input().split())
    L.append(l)
    R.append(r)

res = 0
for i in range(1, n+1):
    if max(L) <= i <= min(R):
        res += 1
print(res)

Fixed submission:
n, m = map(int, input().split())
L, R = [], []
for _ in range(m):
    l,r = map(int, input().split())
    L.append(l)
    R.append(r)


res = min(R) - max(L) + 1
if res < 0:
    print(0)
else:
    print(res)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
gates = [list(map(int, input().split())) for _ in range(m)]

res = 0
for i in range(n):
    flag = False
    for j in range(m):
        if gates[j][0]-1 <= i < gates[j][1]:
            flag = True
        else:
            flag = False
            break
    
    if flag == True:
        res += 1

print(res)

Fixed submission:
n, m = map(int, input().split())
L, R = [], []
for _ in range(m):
    l,r = map(int, input().split())
    L.append(l)
    R.append(r)


res = min(R) - max(L) + 1
if res < 0:
    print(0)
else:
    print(res)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
gates = []
for _ in range(m):
    l, r = map(int, input().split())
    #gates.append(list(range(l-1, r)))
    gates.append([l-1, r])

res = 0
for i in range(n):
    flag = False
    for j in range(m):
        if gates[j][0] <= i < gates[j][1]:
            flag = True
        else:
            flag = False
            break
    
    if flag == True:
        res += 1

print(res)

Fixed submission:
n, m = map(int, input().split())
L, R = [], []
for _ in range(m):
    l,r = map(int, input().split())
    L.append(l)
    R.append(r)


res = min(R) - max(L) + 1
if res < 0:
    print(0)
else:
    print(res)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
gates = []
for _ in range(m):
    l, r = map(int, input().split())
    #gates.append(list(range(l-1, r)))
    gates.append([l-1, r])

res = 0
for i in range(n):
    flag = False
    for j in range(m):
        if gates[j][0] <= i < gates[j][1]:
            flag = True
        else:
            flag = False
            break
    
    if flag == True:
        res += 1

print(res)

Fixed submission:
n, m = map(int, input().split())
L, R = [], []
for _ in range(m):
    l,r = map(int, input().split())
    L.append(l)
    R.append(r)


res = min(R) - max(L) + 1
if res < 0:
    print(0)
else:
    print(res)