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

LR = [list(map(int, input().split())) for _ in range(M)]



left = 1

right = N



for l, r in LR:

    left = max(left, l)

    right = min(right, r)



ans = right - left



print((ans + 1 if ans >= 0 else 0))

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

LR = [list(map(int, input().split())) for _ in range(M)]



left = 1

right = N



for l, r in LR:

    if left < l:

        left = l

    if right > r:

        right = r



ans = right - left



print((ans + 1 if ans >= 0 else 0))

N, M = list(map(int, input().split()))
LR = [list(map(int, input().split())) for _ in range(M)]
left = 1
right = N
for l, r in LR:
    left = max(left, l)
    right = min(right, r)
ans = right - left
print((ans + 1 if ans >= 0 else 0))

N, M = list(map(int, input().split()))
LR = [list(map(int, input().split())) for _ in range(M)]
left = 1
right = N
for l, r in LR:
    if left < l:
        left = l
    if right > r:
        right = r
ans = right - left
print((ans + 1 if ans >= 0 else 0))

-    left = max(left, l) -    right = min(right, r) +    if left < l: +        left = l +    if right > r: +        right = r