Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
L_list = []
R_list = []
count = 0
M_list = list(range(M))
for i in M_list:
    L,R=map(int,input().split())
    L_list.append(L)
    R_list.append(R)


for i in range(1,N+1):
    for j in M_list:
        if(i >= L_list[j] and i<=R_list[j]):
           
            if j==M-1:
                count+=1
        else:
            break
print(count)

Fixed submission:
N,M = map(int,input().split())
L_list = []
R_list = []
count = 0
min_mn=float('inf')
max_mn=0
for i in range(M):
    L,R=map(int,input().split())
    min_mn = min(min_mn,R)
    max_mn = max(max_mn,L)

for i in range(1,N+1):
    if(i>=max_mn and i<=min_mn):
        count += 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
L_list = []
R_list = []
count = 0

for i in range(M):
    L,R=map(int,input().split())
    L_list.append(L)
    R_list.append(R)

for i in range(1,N+1):
    for j in range(M):
        if(i >= L_list[j] and i<=R_list[j]):
           
            if j==M-1:
                count+=1
        else:
            break
print(count)

Fixed submission:
N,M = map(int,input().split())
L_list = []
R_list = []
count = 0
min_mn=float('inf')
max_mn=0
for i in range(M):
    L,R=map(int,input().split())
    min_mn = min(min_mn,R)
    max_mn = max(max_mn,L)

for i in range(1,N+1):
    if(i>=max_mn and i<=min_mn):
        count += 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
L_list = []
R_list = []
count = 0
for i in range(M):
    L,R=map(int,input().split())
    L_list.append(L)
    R_list.append(R)

for i in range(1,N+1):

    for j in range(M):
        if(i in range(L_list[j],R_list[j]+1)):
            if j==M-1:
                count+=1
        else:
            break
print(count)

Fixed submission:
N,M = map(int,input().split())
L_list = []
R_list = []
count = 0
min_mn=float('inf')
max_mn=0
for i in range(M):
    L,R=map(int,input().split())
    min_mn = min(min_mn,R)
    max_mn = max(max_mn,L)

for i in range(1,N+1):
    if(i>=max_mn and i<=min_mn):
        count += 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
'''
4 2
1 3
2 4
'''

N,M = map(int,input().split())
L_list = []
R_list = []
count = 0
for i in range(M):
    L,R=map(int,input().split())
    L_list.append(L)
    R_list.append(R)

for i in range(1,N+1):

    for j in range(M):
        if(i in range(L_list[j],R_list[j]+1)):
            if j==M-1:
                count+=1
        else:
            break
print(count)

Fixed submission:
N,M = map(int,input().split())
L_list = []
R_list = []
count = 0
min_mn=float('inf')
max_mn=0
for i in range(M):
    L,R=map(int,input().split())
    min_mn = min(min_mn,R)
    max_mn = max(max_mn,L)

for i in range(1,N+1):
    if(i>=max_mn and i<=min_mn):
        count += 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
'''
4 2
1 3
2 4
'''

N,M = map(int,input().split())
L_list = []
R_list = []
count = 0
check= True
for i in range(M):
    L,R=map(int,input().split())
    L_list.append(L)
    R_list.append(R)

for i in range(1,N+1):
    check = True
    for j in range(M):
        if(i in range(L_list[j],R_list[j]+1)):
            if check:
                if j==M-1:
                    count+=1
        else:
            check = False
print(count)

Fixed submission:
N,M = map(int,input().split())
L_list = []
R_list = []
count = 0
min_mn=float('inf')
max_mn=0
for i in range(M):
    L,R=map(int,input().split())
    min_mn = min(min_mn,R)
    max_mn = max(max_mn,L)

for i in range(1,N+1):
    if(i>=max_mn and i<=min_mn):
        count += 1
print(count)