f=lambda:list(map(int,input().split()))

_,m=f()

l,r=list(zip(*[f() for _ in range(m)]))

print((max(0,min(r)-max(l)+1)))
f=lambda:list(map(int,input().split()))

n,m=f()

L,R=0,n

for i in range(m):

  l,r=f()

  L=max(L,l)

  R=min(R,r)

print((max(0,R-L+1)))
f = lambda: list(map(int, input().split()))
_, m = f()
l, r = list(zip(*[f() for _ in range(m)]))
print((max(0, min(r) - max(l) + 1)))

f = lambda: list(map(int, input().split()))
n, m = f()
L, R = 0, n
for i in range(m):
    l, r = f()
    L = max(L, l)
    R = min(R, r)
print((max(0, R - L + 1)))

-_, m = f() -l, r = list(zip(*[f() for _ in range(m)])) -print((max(0, min(r) - max(l) + 1))) +n, m = f() +L, R = 0, n +for i in range(m): +    l, r = f() +    L = max(L, l) +    R = min(R, r) +print((max(0, R - L + 1)))