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

L = 0

R = N

for i in range(M):

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

    L = max(L, l)

    R = min(R, r)



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



L_largest = 0

R_min = N

for m in range(M):

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

    if L >= L_largest:

        L_largest = L

    if R <= R_min:

        R_min = R



print((max(0, R_min - L_largest + 1)))
N, M = list(map(int, input().split()))
L = 0
R = N
for i in range(M):
    l, r = list(map(int, input().split()))
    L = max(L, l)
    R = min(R, r)
print((max(0, R - L + 1)))

N, M = list(map(int, input().split()))
L_largest = 0
R_min = N
for m in range(M):
    L, R = list(map(int, input().split()))
    if L >= L_largest:
        L_largest = L
    if R <= R_min:
        R_min = R
print((max(0, R_min - L_largest + 1)))

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