n, m = [int(i) for i in input().split()]

lr = [[int(i) for i in input().split()] for j in range(m)]

l = max(x[0] for x in lr)

r = min(x[1] for x in lr)

print((max(0, r - l + 1)))

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

lmax, rmin = 0, n

for _ in range(m):

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

    lmax = max(l, lmax)

    rmin = min(r, rmin)

print((max(rmin - lmax + 1, 0)))

n, m = [int(i) for i in input().split()]
lr = [[int(i) for i in input().split()] for j in range(m)]
l = max(x[0] for x in lr)
r = min(x[1] for x in lr)
print((max(0, r - l + 1)))

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

-n, m = [int(i) for i in input().split()] -lr = [[int(i) for i in input().split()] for j in range(m)] -l = max(x[0] for x in lr) -r = min(x[1] for x in lr) -print((max(0, r - l + 1))) +n, m = list(map(int, input().split())) +lmax, rmin = 0, n +for _ in range(m): +    l, r = list(map(int, input().split())) +    lmax = max(l, lmax) +    rmin = min(r, rmin) +print((max(rmin - lmax + 1, 0)))