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

L, R = [], []

low = -float('INF')

high = float('INF')

for i in range(M):

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

    L.append(l)

    R.append(r)

    if l > low:

        low = l

    if r < high:

        high = r

print((max(0, high - low + 1)))

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

low = -float('INF')

high = float('INF')

for i in range(M):

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

    if l > low:

        low = l

    if r < high:

        high = r

print((max(0, high - low + 1)))

N, M = list(map(int, input().split()))
L, R = [], []
low = -float("INF")
high = float("INF")
for i in range(M):
    l, r = list(map(int, input().split()))
    L.append(l)
    R.append(r)
    if l > low:
        low = l
    if r < high:
        high = r
print((max(0, high - low + 1)))

N, M = list(map(int, input().split()))
low = -float("INF")
high = float("INF")
for i in range(M):
    l, r = list(map(int, input().split()))
    if l > low:
        low = l
    if r < high:
        high = r
print((max(0, high - low + 1)))

-L, R = [], [] -    L.append(l) -    R.append(r)