a,b= list(map(int,input().split()))

x, y= list(zip(*[list(map(int,input().split())) for i in range(b)]))

f=  min(y) - max(x) 

if f< 0 :

  print((0))

else :

  print((min(y) - max(x) +1))

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

low = 0

high = n+1



for i in range(m):

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

    low = max(low, l)

    high = min(high, r)



print((high-low+1 if low <= high else 0))
a, b = list(map(int, input().split()))
x, y = list(zip(*[list(map(int, input().split())) for i in range(b)]))
f = min(y) - max(x)
if f < 0:
    print((0))
else:
    print((min(y) - max(x) + 1))

n, m = list(map(int, input().split()))
low = 0
high = n + 1
for i in range(m):
    l, r = list(map(int, input().split()))
    low = max(low, l)
    high = min(high, r)
print((high - low + 1 if low <= high else 0))

-a, b = list(map(int, input().split())) -x, y = list(zip(*[list(map(int, input().split())) for i in range(b)])) -f = min(y) - max(x) -if f < 0: -    print((0)) -else: -    print((min(y) - max(x) + 1)) +n, m = list(map(int, input().split())) +low = 0 +high = n + 1 +for i in range(m): +    l, r = list(map(int, input().split())) +    low = max(low, l) +    high = min(high, r) +print((high - low + 1 if low <= high else 0))