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

lmin = 0

lmax = 1e5+10

for _ in range(m):

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

  lmin = max(lmin, l)

  lmax = min(lmax, r)

print((max(0, lmax-lmin+1)))
n, m, *ls = list(map(int, open(0).read().split()))

l = max(ls[0::2])

r = min(ls[1::2])

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

n, m, *ls = list(map(int, open(0).read().split()))
l = max(ls[0::2])
r = min(ls[1::2])
print((max(0, r - l + 1)))

-n, m = list(map(int, input().split())) -lmin = 0 -lmax = 1e5 + 10 -for _ in range(m): -    l, r = list(map(int, input().split())) -    lmin = max(lmin, l) -    lmax = min(lmax, r) -print((max(0, lmax - lmin + 1))) +n, m, *ls = list(map(int, open(0).read().split())) +l = max(ls[0::2]) +r = min(ls[1::2]) +print((max(0, r - l + 1)))