n,m = list(map(int, input().split()))

ans = 0

L = 1

R = n

for i in range(m):

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

    L = max(l,L)

    R = min(r,R)

    

if L <= R:

    print((R-L+1))

else:

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

left=0

right=N



for i in range(M):

    L, R = list(map(int, input().split()))

    if L > left:

        left = L

    if R < right:

        right = R



if left <= right:

    print((right-left+1))

else:

    print((0))
n, m = list(map(int, input().split()))
ans = 0
L = 1
R = n
for i in range(m):
    l, r = list(map(int, input().split()))
    L = max(l, L)
    R = min(r, R)
if L <= R:
    print((R - L + 1))
else:
    print((0))

N, M = list(map(int, input().split()))
left = 0
right = N
for i in range(M):
    L, R = list(map(int, input().split()))
    if L > left:
        left = L
    if R < right:
        right = R
if left <= right:
    print((right - left + 1))
else:
    print((0))

-n, m = list(map(int, input().split())) -ans = 0 -L = 1 -R = n -for i in range(m): -    l, r = list(map(int, input().split())) -    L = max(l, L) -    R = min(r, R) -if L <= R: -    print((R - L + 1)) +N, M = list(map(int, input().split())) +left = 0 +right = N +for i in range(M): +    L, R = list(map(int, input().split())) +    if L > left: +        left = L +    if R < right: +        right = R +if left <= right: +    print((right - left + 1))