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

ansl = 0

ansr = n+1

for i in range(m):

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

    ansl = max(ansl,l)

    ansr = min(ansr,r)

print((0 if ansl > ansr else ansr-ansl+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)

ansl = max(L)

ansr = min(R)

print((0 if ansl > ansr else ansr-ansl+1))
n, m = list(map(int, input().split()))
ansl = 0
ansr = n + 1
for i in range(m):
    l, r = list(map(int, input().split()))
    ansl = max(ansl, l)
    ansr = min(ansr, r)
print((0 if ansl > ansr else ansr - ansl + 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)
ansl = max(L)
ansr = min(R)
print((0 if ansl > ansr else ansr - ansl + 1))

-ansl = 0 -ansr = n + 1 +L = [] +R = [] -    ansl = max(ansl, l) -    ansr = min(ansr, r) +    L.append(l) +    R.append(r) +ansl = max(L) +ansr = min(R)