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

Ls,Rs = [],[]

for i in range(M):

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

    Ls.append(L)

    Rs.append(R)



print((max(0,min(Rs)-max(Ls)+1)))


"""

imos

"""

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

from itertools import accumulate

imos = [0]*(N+2)

for i in range(M):

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

    imos[L] += 1

    imos[R+1] -= 1

acc = list(accumulate(imos))

print((sum([1 for a in acc if a == M])))
N, M = list(map(int, input().split()))
Ls, Rs = [], []
for i in range(M):
    L, R = list(map(int, input().split()))
    Ls.append(L)
    Rs.append(R)
print((max(0, min(Rs) - max(Ls) + 1)))

"""
imos
"""
N, M = list(map(int, input().split()))
from itertools import accumulate

imos = [0] * (N + 2)
for i in range(M):
    L, R = list(map(int, input().split()))
    imos[L] += 1
    imos[R + 1] -= 1
acc = list(accumulate(imos))
print((sum([1 for a in acc if a == M])))

+""" +imos +""" -Ls, Rs = [], [] +from itertools import accumulate + +imos = [0] * (N + 2) -    Ls.append(L) -    Rs.append(R) -print((max(0, min(Rs) - max(Ls) + 1))) +    imos[L] += 1 +    imos[R + 1] -= 1 +acc = list(accumulate(imos)) +print((sum([1 for a in acc if a == M])))