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

L = [0 for i in range(N+1)]

R = [0 for i in range(N+1)]

for i in range(M):

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

    L[l] += 1

    R[r] += 1

cnt = 0

tmp = 0

for i in range(N+1):

    tmp += L[i]

    if tmp == M:

        cnt += 1

    tmp -= R[i]

print(cnt)

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

ll = 1

rr = n

for i in range(m):

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

    if l > ll:

        ll = l

    if r < rr:

        rr = r

print((max(rr - ll + 1, 0)))

N, M = list(map(int, input().split()))
L = [0 for i in range(N + 1)]
R = [0 for i in range(N + 1)]
for i in range(M):
    l, r = list(map(int, input().split()))
    L[l] += 1
    R[r] += 1
cnt = 0
tmp = 0
for i in range(N + 1):
    tmp += L[i]
    if tmp == M:
        cnt += 1
    tmp -= R[i]
print(cnt)

n, m = list(map(int, input().split()))
ll = 1
rr = n
for i in range(m):
    l, r = list(map(int, input().split()))
    if l > ll:
        ll = l
    if r < rr:
        rr = r
print((max(rr - ll + 1, 0)))

-N, M = list(map(int, input().split())) -L = [0 for i in range(N + 1)] -R = [0 for i in range(N + 1)] -for i in range(M): +n, m = list(map(int, input().split())) +ll = 1 +rr = n +for i in range(m): -    L[l] += 1 -    R[r] += 1 -cnt = 0 -tmp = 0 -for i in range(N + 1): -    tmp += L[i] -    if tmp == M: -        cnt += 1 -    tmp -= R[i] -print(cnt) +    if l > ll: +        ll = l +    if r < rr: +        rr = r +print((max(rr - ll + 1, 0)))