Buggy python submission (verdict: Time Limit Exceeded):
n, m = list(map(int, input().split()))
l = []
r = []
for i in range(m):
    x, y=[int(i) for i in input().split()]
    l.append(x)
    r.append(y)
ans = 0
'''
for i in range(n):
    cnt = 0
    for j in range(m):

        for k in range(l[j], r[j]+1):
            if i + 1 == k:
                cnt += 1
        if cnt == m:
            ans += 1
print(ans)
'''
for i in range(n):
    cnt = 0
    #print('cnt rrr')
    #print('i=' + str(i))
    for j in range(m):
        #print(l[j], end=' ')
        #print(r[j])
        if i + 1 >= l[j] and r[j] >= i + 1:
            cnt += 1
            #print('cnt='+ str(cnt))
        else:
            #print('break')
            break
    if cnt == m:
        ans += 1
print(ans)


Fixed submission:
n, m = list(map(int, input().split()))
maxl = 0
minr = 1000000
for i in range(m):
    l, r = list(map(int, input().split()))
    maxl = max(maxl, l)
    minr = min(minr, r)
if minr < maxl:
    print(0)
else:
    print(minr - maxl + 1)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = list(map(int, input().split()))
l = []
r = []
for i in range(m):
    x, y=[int(i) for i in input().split()]
    l.append(x)
    r.append(y)
ans = 0
'''
for i in range(n):
    cnt = 0
    for j in range(m):

        for k in range(l[j], r[j]+1):
            if i + 1 == k:
                cnt += 1
        if cnt == m:
            ans += 1
print(ans)
'''
for i in range(n):
    cnt = 0
    #print('cnt rrr')
    #print('i=' + str(i))
    for j in range(m):
        #print(l[j], end=' ')
        #print(r[j])
        if i + 1 >= l[j] and r[j] >= i + 1:
            cnt += 1
            #print('cnt='+ str(cnt))
        else:
            #print('break')
            break
    if cnt == m:
        ans += 1
print(ans)


Fixed submission:
n, m = list(map(int, input().split()))
maxl = 0
minr = 1000000
for i in range(m):
    l, r = list(map(int, input().split()))
    maxl = max(maxl, l)
    minr = min(minr, r)
if minr < maxl:
    print(0)
else:
    print(minr - maxl + 1)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = list(map(int, input().split()))
l = []
r = []
for i in range(m):
    x, y=[int(i) for i in input().split()]
    l.append(x)
    r.append(y)
ans = 0
for i in range(n):
    cnt = 0
    for j in range(m):

        for k in range(l[j], r[j]+1):
            if i + 1 == k:
                cnt += 1
        if cnt == m:
            ans += 1
print(ans)

Fixed submission:
n, m = list(map(int, input().split()))
maxl = 0
minr = 1000000
for i in range(m):
    l, r = list(map(int, input().split()))
    maxl = max(maxl, l)
    minr = min(minr, r)
if minr < maxl:
    print(0)
else:
    print(minr - maxl + 1)

Buggy python submission (verdict: Runtime Error):
n, m = list(map(int, input().split()))
l = []
r = []
for i in range(m):
    x, y=[int(i) for i in input().split()]
    l.append(x)
    r.append(y)
ans = 0
for i in range(n):
    cnt = 0
    for j in range(m):

        for k in range(l[j], r[j]+1):S
            if i + 1 == k:
                cnt += 1
        if cnt == m:
            ans += 1
print(ans)

Fixed submission:
n, m = list(map(int, input().split()))
maxl = 0
minr = 1000000
for i in range(m):
    l, r = list(map(int, input().split()))
    maxl = max(maxl, l)
    minr = min(minr, r)
if minr < maxl:
    print(0)
else:
    print(minr - maxl + 1)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = list(map(int, input().split()))
l = []
r = []
for i in range(m):
    x, y=[int(i) for i in input().split()]
    l.append(x)
    r.append(y)
ans = 0
for i in range(n):
    cnt = 0
    #print('i=' + str(i))
    for j in range(m):
        #print(l[j], end=' ')
        #print(r[j])
        if i + 1 < l[j] or r[j] < i + 1:
            pass
        else:
            cnt += 1
            #print('cnt='+ str(cnt))
    if cnt == m:
        ans += 1
print(ans)


Fixed submission:
n, m = list(map(int, input().split()))
maxl = 0
minr = 1000000
for i in range(m):
    l, r = list(map(int, input().split()))
    maxl = max(maxl, l)
    minr = min(minr, r)
if minr < maxl:
    print(0)
else:
    print(minr - maxl + 1)