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

A = [list(map(int,input().split())) for i in range(M)]



l = -1

r = float("inf")



for x,y in A :

    if l < x :

        l = x

    if y < r :

        r = y

print((max(0,r-l+1)))

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



L = []

R = []



for i in range(M) :

    l,r = list(map(int,input().split()))

    L.append(l)

    R.append(r)



left = max(L)

right = min(R)



ans = max(0, right-left+1)



print(ans)
N, M = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(M)]
l = -1
r = float("inf")
for x, y in A:
    if l < x:
        l = x
    if y < r:
        r = y
print((max(0, r - l + 1)))

N, M = list(map(int, input().split()))
L = []
R = []
for i in range(M):
    l, r = list(map(int, input().split()))
    L.append(l)
    R.append(r)
left = max(L)
right = min(R)
ans = max(0, right - left + 1)
print(ans)

-A = [list(map(int, input().split())) for i in range(M)] -l = -1 -r = float("inf") -for x, y in A: -    if l < x: -        l = x -    if y < r: -        r = y -print((max(0, r - l + 1))) +L = [] +R = [] +for i in range(M): +    l, r = list(map(int, input().split())) +    L.append(l) +    R.append(r) +left = max(L) +right = min(R) +ans = max(0, right - left + 1) +print(ans)