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

L,R = [],[]

for i in range(M):

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

    L.append(l)

    R.append(r)

ans = min(R)-max(L)+1

print((ans if ans >= 0 else 0))
# coding: utf-8

import sys



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



N, M = lr()

L = 0; R = 10 ** 6

for _ in range(M):

    l, r = lr()

    if l > L:

        L = l

    if r < R:

        R = r



answer = max(0, R - L + 1)

print(answer)

N, M = list(map(int, input().split()))
L, R = [], []
for i in range(M):
    l, r = list(map(int, input().split()))
    L.append(l)
    R.append(r)
ans = min(R) - max(L) + 1
print((ans if ans >= 0 else 0))

# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, M = lr()
L = 0
R = 10**6
for _ in range(M):
    l, r = lr()
    if l > L:
        L = l
    if r < R:
        R = r
answer = max(0, R - L + 1)
print(answer)

-N, M = list(map(int, input().split())) -L, R = [], [] -for i in range(M): -    l, r = list(map(int, input().split())) -    L.append(l) -    R.append(r) -ans = min(R) - max(L) + 1 -print((ans if ans >= 0 else 0)) +# coding: utf-8 +import sys + +sr = lambda: sys.stdin.readline().rstrip() +ir = lambda: int(sr()) +lr = lambda: list(map(int, sr().split())) +N, M = lr() +L = 0 +R = 10**6 +for _ in range(M): +    l, r = lr() +    if l > L: +        L = l +    if r < R: +        R = r +answer = max(0, R - L + 1) +print(answer)