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()))



left = 1

right = N



for _ in range(M):

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



    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:
    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()))
left = 1
right = N
for _ in range(M):
    l, r = list(map(int, input().split()))
    if left < l:
        left = l
    if right > r:
        right = r
ans = right - left
print((ans + 1 if ans >= 0 else 0))

-LR = [list(map(int, input().split())) for _ in range(M)] -for l, r in LR: +for _ in range(M): +    l, r = list(map(int, input().split()))