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