Buggy python submission (verdict: Runtime Error):
import sys
 
N, M = map(int,input().split())
 
ls = []
 
L, R = map(int,input().split())
l = [k+L for k in range(R-L+1)]
 
if M == 1:
    print(len(l))
else:
    cs = []
    for i in range(M-1):
        L, R = map(int,input().split())
        if L in l:
            c = l[-1] - L + 1
            if c <= 0:
                print(0)
                sys.exit()
            cs.append(c)
 
    print(min(cs))

Fixed submission:
N, M = map(int,input().split())

Ls, Rs = [0 for _ in range(M)],  [0 for _ in range(M)]

for i in range(M):
    L, R = map(int,input().split())
    Ls[i] = L
    Rs[i] = R
    
L_prime = max(Ls)
R_peime = min(Rs)

if L_prime > R_peime:
    print(0)
else:
    print(R_peime - L_prime + 1)

Buggy python submission (verdict: Runtime Error):
import sys

N, M = map(int,input().split())

ls = []

L, R = map(int,input().split())
l = [k+L for k in range(R-L+1)]

if M == 1:
    print(len(l))
else:
  	cs = []
    for i in range(M-1):
        L, R = map(int,input().split())
        if L in l:
            c = l[-1] - L + 1
            if c <= 0:
                print(0)
                sys.exit()
            cs.append(c)

    print(min(cs))

Fixed submission:
N, M = map(int,input().split())

Ls, Rs = [0 for _ in range(M)],  [0 for _ in range(M)]

for i in range(M):
    L, R = map(int,input().split())
    Ls[i] = L
    Rs[i] = R
    
L_prime = max(Ls)
R_peime = min(Rs)

if L_prime > R_peime:
    print(0)
else:
    print(R_peime - L_prime + 1)

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

ls = []

L, R = map(int,input().split())
l = [k+L for k in range(R-L+1)]

cs = []

if M == 1:
    print(len(l))
else:
    for i in range(M-1):
        L, R = map(int,input().split())
        if L in l:
            c = l[-1] - L + 1
            cs.append(c)

    print(min(cs))

Fixed submission:
N, M = map(int,input().split())

Ls, Rs = [0 for _ in range(M)],  [0 for _ in range(M)]

for i in range(M):
    L, R = map(int,input().split())
    Ls[i] = L
    Rs[i] = R
    
L_prime = max(Ls)
R_peime = min(Rs)

if L_prime > R_peime:
    print(0)
else:
    print(R_peime - L_prime + 1)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import copy

N, M = map(int,input().split())

Ls, Rs = [0 for _ in range(M)],  [0 for _ in range(M)]

for i in range(M):
    L, R = map(int,input().split())
    Ls[i] = L
    Rs[i] = R
    
    if i != 0:
        if Rs[i-1] < Ls[i]:
            print(0)
            sys.exit( )
ls = []

for i in range(M):
    l = [k+Ls[i] for k in range(Rs[i]-Ls[i]+1)]
    ls.append(l)
    
if M == 1:
    print(len(l))
else:
    for i in range(M-1):
        l_set = set(ls[i]) & set(ls[i+1])
        ls[i+1] = copy.deepcopy(l_set)

    print(len(l_set))

Fixed submission:
N, M = map(int,input().split())

Ls, Rs = [0 for _ in range(M)],  [0 for _ in range(M)]

for i in range(M):
    L, R = map(int,input().split())
    Ls[i] = L
    Rs[i] = R
    
L_prime = max(Ls)
R_peime = min(Rs)

if L_prime > R_peime:
    print(0)
else:
    print(R_peime - L_prime + 1)

Buggy python submission (verdict: Time Limit Exceeded):
import copy

N, M = map(int,input().split())

if M == 1:
    L, R = map(int,input().split())
    l = [k+L for k in range(R-L+1)]
    print(len(l))
else:
    L, R = map(int,input().split())
    l = [k+L for k in range(R-L+1)]
    l_tmp = copy.deepcopy(l)

    L, R = map(int,input().split())
    l = [k+L for k in range(R-L+1)]

    l_set = list(set(l) & set(l_tmp))
    l_tmp = copy.deepcopy(l)
    
    for i in range(M-2):
        L, R = map(int,input().split())
        l = [k+L for k in range(R-L+1)]

        l_set = list(set(l) & set(l_set))
        l_tmp = copy.deepcopy(l)
        
        if len(l_set) == 0:
            break

    print(len(l_set))

Fixed submission:
N, M = map(int,input().split())

Ls, Rs = [0 for _ in range(M)],  [0 for _ in range(M)]

for i in range(M):
    L, R = map(int,input().split())
    Ls[i] = L
    Rs[i] = R
    
L_prime = max(Ls)
R_peime = min(Rs)

if L_prime > R_peime:
    print(0)
else:
    print(R_peime - L_prime + 1)

Buggy python submission (verdict: Time Limit Exceeded):
import copy

N, M = map(int,input().split())

ls = []

for i in range(M):
    L, R = map(int,input().split())
    l = [k+L for k in range(R-L+1)]
    ls.append(l)
    
if M == 1:
    print(len(l))
else:
    for i in range(M-1):
        l_set = set(ls[i]) & set(ls[i+1])
        if len(l_set) == 0:
            break
        ls[i+1] = copy.deepcopy(l_set)

    print(len(l_set))

Fixed submission:
N, M = map(int,input().split())

Ls, Rs = [0 for _ in range(M)],  [0 for _ in range(M)]

for i in range(M):
    L, R = map(int,input().split())
    Ls[i] = L
    Rs[i] = R
    
L_prime = max(Ls)
R_peime = min(Rs)

if L_prime > R_peime:
    print(0)
else:
    print(R_peime - L_prime + 1)

Buggy python submission (verdict: Time Limit Exceeded):
import copy

N, M = map(int,input().split())

ls = []

for i in range(M):
    L, R = map(int,input().split())
    l = [k+L for k in range(R-L+1)]
    ls.append(l)

for i in range(M-1):
    l_set = set(ls[i]) & set(ls[i+1])
    ls[i+1] = copy.deepcopy(l_set)

print(len(ls[-1]))

Fixed submission:
N, M = map(int,input().split())

Ls, Rs = [0 for _ in range(M)],  [0 for _ in range(M)]

for i in range(M):
    L, R = map(int,input().split())
    Ls[i] = L
    Rs[i] = R
    
L_prime = max(Ls)
R_peime = min(Rs)

if L_prime > R_peime:
    print(0)
else:
    print(R_peime - L_prime + 1)

Buggy python submission (verdict: Time Limit Exceeded):
import copy

N, M = map(int,input().split())

if M == 1:
    L, R = map(int,input().split())
    l = [k+L for k in range(R-L+1)]
    print(len(l))
else:
    L, R = map(int,input().split())
    l = [k+L for k in range(R-L+1)]
    l_tmp = copy.deepcopy(l)

    L, R = map(int,input().split())
    l = [k+L for k in range(R-L+1)]

    l_set = list(set(l) & set(l_tmp))
    l_tmp = copy.deepcopy(l)
    
    for i in range(M-2):
        L, R = map(int,input().split())
        l = [k+L for k in range(R-L+1)]

        l_set = list(set(l) & set(l_set))
        l_tmp = copy.deepcopy(l)

    print(len(l_set))

Fixed submission:
N, M = map(int,input().split())

Ls, Rs = [0 for _ in range(M)],  [0 for _ in range(M)]

for i in range(M):
    L, R = map(int,input().split())
    Ls[i] = L
    Rs[i] = R
    
L_prime = max(Ls)
R_peime = min(Rs)

if L_prime > R_peime:
    print(0)
else:
    print(R_peime - L_prime + 1)

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

if M == 1:
    L, R = map(int,input().split())
    l = [k+L for k in range(R-L+1)]
    print(len(l))
else:
    L, R = map(int,input().split())
    l = [k+L for k in range(R-L+1)]
    l_tmp = copy.deepcopy(l)

    L, R = map(int,input().split())
    l = [k+L for k in range(R-L+1)]

    l_set = list(set(l) & set(l_tmp))
    l_tmp = copy.deepcopy(l)
    for i in range(M-2):
        L, R = map(int,input().split())
        l = [k+L for k in range(R-L+1)]

        l_set = list(set(l) & set(l_set))
        l_tmp = copy.deepcopy(l)

    print(len(l_set))

Fixed submission:
N, M = map(int,input().split())

Ls, Rs = [0 for _ in range(M)],  [0 for _ in range(M)]

for i in range(M):
    L, R = map(int,input().split())
    Ls[i] = L
    Rs[i] = R
    
L_prime = max(Ls)
R_peime = min(Rs)

if L_prime > R_peime:
    print(0)
else:
    print(R_peime - L_prime + 1)