Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int,input().split())
 
for i in range(m):
    s,t = map(int,input().split())
    if i == 0:
        ans2 = [s,t+1]
    try:
        ans2 = [j for j in range(max(min(ans2),s),min(max(ans2)+1,t+1)) if s <= j <= t]
    except:
        break

print(len(ans2))


Fixed submission:
n,m = map(int,input().split())

left_max = -1
right_min = n+1

for i in range(m):
    s,t = map(int,input().split())
    left_max = max(left_max,s)
    right_min = min(right_min, t)
    
print(max(0, right_min - left_max +1))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int,input().split())
 
l = [""] * m

for i in range(m):
    s,t = map(int,input().split())
    if i == 0:
        ans2 = [s,t+1]
    try:
        ans2 = [j for j in range(max(min(ans2),s),min(max(ans2)+1,t+1)) if s <= j <= t]
    except:
        break


print(len(ans2))


Fixed submission:
n,m = map(int,input().split())

left_max = -1
right_min = n+1

for i in range(m):
    s,t = map(int,input().split())
    left_max = max(left_max,s)
    right_min = min(right_min, t)
    
print(max(0, right_min - left_max +1))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int,input().split())
 
l = [""] * m
ans2 = [1,n]

for i in range(m):
    s,t = map(int,input().split())
    try:
        ans2 = [j for j in range(min(ans2),max(ans2)+1) if s <= j <= t]
    except:
        break


print(len(ans2))


Fixed submission:
n,m = map(int,input().split())

left_max = -1
right_min = n+1

for i in range(m):
    s,t = map(int,input().split())
    left_max = max(left_max,s)
    right_min = min(right_min, t)
    
print(max(0, right_min - left_max +1))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int,input().split())
 
l = [""] * m
ans3 = set([1,n+1])

for i in range(m):
    s,t = map(int,input().split())
    ans2 = [j for j in range(s,t+1) if s <= j <= t]
    if i == 0:
        ans3 = set(ans2)
        ans2.clear()
        if len(ans3) == 0:
            break
    else:
        ans3 = ans3 & set(ans2)
        ans2.clear()
        if len(ans3) == 0:
            break

print(len(ans3))

Fixed submission:
n,m = map(int,input().split())

left_max = -1
right_min = n+1

for i in range(m):
    s,t = map(int,input().split())
    left_max = max(left_max,s)
    right_min = min(right_min, t)
    
print(max(0, right_min - left_max +1))

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

l = [""] * m

for i in range(m):
    l[i] = list(map(int,input().split()))
ans3 = set([0,n+1])

for i in range(m):
    ans2 = [j for j in range(min(ans3),max(ans3)+1) if l[i][0] <= j <= l[i][1]]
    if i == 0:
        ans3 = set(ans2)
    else:
        ans3 = ans3 & set(ans2)
    ans2.clear()
    
print(len(ans3))

Fixed submission:
n,m = map(int,input().split())

left_max = -1
right_min = n+1

for i in range(m):
    s,t = map(int,input().split())
    left_max = max(left_max,s)
    right_min = min(right_min, t)
    
print(max(0, right_min - left_max +1))

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

l = [""] * m

for i in range(m):
    l[i] = list(map(int,input().split()))

ans3 = [i for i in range(1,n+1)]
ans3 = set(ans3)


for i in range(m):
    ans2 = [j for j in range(min(ans3),max(ans3)+1) if l[i][0] <= j <= l[i][1]]
    ans3 = ans3 & set(ans2)
    ans2.clear()
    
print(len(ans3))

Fixed submission:
n,m = map(int,input().split())

left_max = -1
right_min = n+1

for i in range(m):
    s,t = map(int,input().split())
    left_max = max(left_max,s)
    right_min = min(right_min, t)
    
print(max(0, right_min - left_max +1))

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

l = [""] * m

for i in range(m):
    l[i] = list(map(int,input().split()))

ans3 = [i for i in range(1,n+1)]
ans3 = set(ans3)


for i in range(m):
    ans2 = [j for j in range(1,n+1) if l[i][0] <= j <= l[i][1]]
    ans3 = ans3 & set(ans2)
    ans2.clear()
    
    
print(len(ans3))

Fixed submission:
n,m = map(int,input().split())

left_max = -1
right_min = n+1

for i in range(m):
    s,t = map(int,input().split())
    left_max = max(left_max,s)
    right_min = min(right_min, t)
    
print(max(0, right_min - left_max +1))

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

l = [""] * m

for i in range(m):
    l[i] = list(map(int,input().split()))

ans2 = set()
ans3 = set()

for i in range(1,n+1):
    ans3.add(i)

tmp = set()

for i in range(m):
    for j in range(1,n+1):
        if l[i][0] <= j <= l[i][1]:
            ans2.add(j)
    ans3 = ans3 & ans2
    ans2.clear()
    
    
print(len(ans3))


    

Fixed submission:
n,m = map(int,input().split())

left_max = -1
right_min = n+1

for i in range(m):
    s,t = map(int,input().split())
    left_max = max(left_max,s)
    right_min = min(right_min, t)
    
print(max(0, right_min - left_max +1))