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

gate = []

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

for i in range(1, m):

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

    if l < m:

        l = m

    if s < r:

        r = s

print((len([i for i in range(l, r + 1)])))
n, m = list(map(int, input().split()))

l, r = [0] * m, [0] * m

for i in range(m):

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

print((max(min(r) - max(l) + 1, 0)))
n, m = list(map(int, input().split()))
gate = []
l, r = list(map(int, input().split()))
for i in range(1, m):
    m, s = list(map(int, input().split()))
    if l < m:
        l = m
    if s < r:
        r = s
print((len([i for i in range(l, r + 1)])))

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

-gate = [] -l, r = list(map(int, input().split())) -for i in range(1, m): -    m, s = list(map(int, input().split())) -    if l < m: -        l = m -    if s < r: -        r = s -print((len([i for i in range(l, r + 1)]))) +l, r = [0] * m, [0] * m +for i in range(m): +    l[i], r[i] = list(map(int, input().split())) +print((max(min(r) - max(l) + 1, 0)))