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

l = 0

r = N

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

for d in D:

    L,R = d

    if L > l:

        l = L

    if R < r:

        r = R

print((max(r-l+1,0)))
N,M = list(map(int, input().split()))

L,R = [],[]

for _ in range(M):

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

    L.append(l)

    R.append(r)

print((max(min(R)-max(L)+1,0)))
N, M = list(map(int, input().split()))
l = 0
r = N
D = [list(map(int, input().split())) for _ in range(M)]
for d in D:
    L, R = d
    if L > l:
        l = L
    if R < r:
        r = R
print((max(r - l + 1, 0)))

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

-l = 0 -r = N -D = [list(map(int, input().split())) for _ in range(M)] -for d in D: -    L, R = d -    if L > l: -        l = L -    if R < r: -        r = R -print((max(r - l + 1, 0))) +L, R = [], [] +for _ in range(M): +    l, r = list(map(int, input().split())) +    L.append(l) +    R.append(r) +print((max(min(R) - max(L) + 1, 0)))