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

left = 1
right = N

for i in range(M):
    a,b = map(int, input().split())
    left = max(left,a)
    right = min(right, b)

print(max(0,right-left+1))

# imos = [0] * (N + 2)
# for i in range(M):
#     l, r = map(int, input().split())
#     imos[l] += 1
#     imos[r + 1] -= 1
#
# imos = list(accumulate(imos))
#
# ans = 0
# for im in imos:
#     ans += (im == M)
#
# print(ans) from itertools import accumulate N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M left = 1 left 1 right = N right N for i in range(M):
    a,b = map(int, input().split())
    left = max(left,a)
    right = min(right, b) i range(M) range M a,b = map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b left = max(left,a) left max(left,a) max left a right = min(right, b) right min(right, b) min right b print(max(0,right-left+1)) print max(0,right-left+1) max 0 right-left+1 right-left right left 1 left = max(left,a) max(left,a) left right = min(right, b) min(right, b) right M = map(int, input().split()) map(int, input().split()) M b = map(int, input().split()) map(int, input().split()) b a,b = map(int, input().split()) map(int, input().split()) a N, M = map(int, input().split()) map(int, input().split()) N left = 1 1 left right = N N right
from itertools import accumulate
N, M = map(int, input().split())

left = 1
right = N

for i in range(M):
    a,b = map(int, input().split())
    left = max(left,a)
    right = min(right, b)

print(max(0,right-left+1))

# imos = [0] * (N + 2)
# for i in range(M):
#     l, r = map(int, input().split())
#     imos[l] += 1
#     imos[r + 1] -= 1
#
# imos = list(accumulate(imos))
#
# ans = 0
# for im in imos:
#     ans += (im == M)
#
# print(ans)
