N, M = list(map(int, input().split()))



left = 1

right = N

# 1-indexed

# [left, right]



for _ in range(M):

    L, R = list(map(int, input().split()))

    if L > left:

        left = L

    if R < right:

        right = R

    if right - left + 1 <= 0:

        break

print((max(0, right - left + 1)))

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



l, r = [], []

for _ in range(m):

    ll, rr = list(map(int, input().split()))

    l.append(ll)

    r.append(rr)



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

N, M = list(map(int, input().split()))
left = 1
right = N
# 1-indexed
# [left, right]
for _ in range(M):
    L, R = list(map(int, input().split()))
    if L > left:
        left = L
    if R < right:
        right = R
    if right - left + 1 <= 0:
        break
print((max(0, right - left + 1)))

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

-N, M = list(map(int, input().split())) -left = 1 -right = N -# 1-indexed -# [left, right] -for _ in range(M): -    L, R = list(map(int, input().split())) -    if L > left: -        left = L -    if R < right: -        right = R -    if right - left + 1 <= 0: -        break -print((max(0, right - left + 1))) +n, m = list(map(int, input().split())) +l, r = [], [] +for _ in range(m): +    ll, rr = list(map(int, input().split())) +    l.append(ll) +    r.append(rr) +print((max(0, min(r) - max(l) + 1)))