# ABC127C - Prison

# l-max < i < r-min -> count i

n, m = list(map(int, input().rstrip().split()))

lst = [list(map(int, input().rstrip().split())) for _ in range(m)]

l, r = lst[0][0], lst[0][1]

for i in lst[1:]:

    l = max(l, i[0])

    r = min(r, i[1])

print((max(0, r - l + 1)))
# ABC127C - Prison

# l-max < i < r-min -> max(0, r - l + 1)

import sys

input = sys.stdin.readline



n, m = list(map(int, input().rstrip().split()))

lst = [list(map(int, input().rstrip().split())) for _ in range(m)]

l, r = lst[0][0], lst[0][1]

for i in lst[1:]:

    l = max(l, i[0])

    r = min(r, i[1])

print((max(0, r - l + 1)))
# ABC127C - Prison
# l-max < i < r-min -> count i
n, m = list(map(int, input().rstrip().split()))
lst = [list(map(int, input().rstrip().split())) for _ in range(m)]
l, r = lst[0][0], lst[0][1]
for i in lst[1:]:
    l = max(l, i[0])
    r = min(r, i[1])
print((max(0, r - l + 1)))

# ABC127C - Prison
# l-max < i < r-min -> max(0, r - l + 1)
import sys

input = sys.stdin.readline
n, m = list(map(int, input().rstrip().split()))
lst = [list(map(int, input().rstrip().split())) for _ in range(m)]
l, r = lst[0][0], lst[0][1]
for i in lst[1:]:
    l = max(l, i[0])
    r = min(r, i[1])
print((max(0, r - l + 1)))

-# l-max < i < r-min -> count i +# l-max < i < r-min -> max(0, r - l + 1) +import sys + +input = sys.stdin.readline