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

l_max = 1

r_min = n

for _ in range(m):

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

    l_max = max(l_max, l)

    r_min = min(r_min, r)

    

print((max(0,r_min-l_max+1)))
n, m = list(map(int, input().split()))

max_l = 0

min_r = n

for _ in range(m):

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

    max_l = max(l, max_l)

    min_r = min(r, min_r)

print((max(min_r - max_l + 1, 0)))
n, m = list(map(int, input().split()))
l_max = 1
r_min = n
for _ in range(m):
    l, r = list(map(int, input().split()))
    l_max = max(l_max, l)
    r_min = min(r_min, r)
print((max(0, r_min - l_max + 1)))

n, m = list(map(int, input().split()))
max_l = 0
min_r = n
for _ in range(m):
    l, r = list(map(int, input().split()))
    max_l = max(l, max_l)
    min_r = min(r, min_r)
print((max(min_r - max_l + 1, 0)))

-l_max = 1 -r_min = n +max_l = 0 +min_r = n -    l_max = max(l_max, l) -    r_min = min(r_min, r) -print((max(0, r_min - l_max + 1))) +    max_l = max(l, max_l) +    min_r = min(r, min_r) +print((max(min_r - max_l + 1, 0)))