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)

L.sort()

R.sort()

print((0 if R[0]<L[-1] else R[0]-L[-1]+1))
N,M=list(map(int,input().split()))

L=0

R=10**9

for _ in range(M):

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

    L=max(L,l)

    R=min(R,r)

print((0 if R<L else R-L+1))
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)
L.sort()
R.sort()
print((0 if R[0] < L[-1] else R[0] - L[-1] + 1))

N, M = list(map(int, input().split()))
L = 0
R = 10**9
for _ in range(M):
    l, r = list(map(int, input().split()))
    L = max(L, l)
    R = min(R, r)
print((0 if R < L else R - L + 1))

-L = [] -R = [] +L = 0 +R = 10**9 -    L.append(l) -    R.append(r) -L.sort() -R.sort() -print((0 if R[0] < L[-1] else R[0] - L[-1] + 1)) +    L = max(L, l) +    R = min(R, r) +print((0 if R < L else R - L + 1))