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

ansl = 1

ansr = N

for _ in range(M):

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

    ansl = max(ansl, L)

    ansr = min(ansr, R)

ans = max(ansr - ansl + 1, 0)

print(ans)
import sys

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

ansl = 1

ansr = N

for _ in range(M):

    l, r = list(map(int, sys.stdin.readline().split()))

    ansl = max(ansl, l)

    ansr = min(ansr, r)

ans = max(0, ansr - ansl + 1)

print(ans)
N, M = list(map(int, input().split()))
ansl = 1
ansr = N
for _ in range(M):
    L, R = list(map(int, input().split()))
    ansl = max(ansl, L)
    ansr = min(ansr, R)
ans = max(ansr - ansl + 1, 0)
print(ans)

import sys

N, M = list(map(int, input().split()))
ansl = 1
ansr = N
for _ in range(M):
    l, r = list(map(int, sys.stdin.readline().split()))
    ansl = max(ansl, l)
    ansr = min(ansr, r)
ans = max(0, ansr - ansl + 1)
print(ans)

+import sys + -    L, R = list(map(int, input().split())) -    ansl = max(ansl, L) -    ansr = min(ansr, R) -ans = max(ansr - ansl + 1, 0) +    l, r = list(map(int, sys.stdin.readline().split())) +    ansl = max(ansl, l) +    ansr = min(ansr, r) +ans = max(0, ansr - ansl + 1)