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

left, right = 1, n

for _ in range(m):

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

  if l > left:

    left = l

  if r < right:

    right = r

  if left > right:

    print((0))

    quit()

print((right - left + 1))
import sys

n, m, *lst = list(map(int, sys.stdin.read().split()))

l = max(lst[::2])

r = min(lst[1::2])

if l > r:

  print((0))

else:

  print((r - l + 1))

n, m = list(map(int, input().split()))
left, right = 1, n
for _ in range(m):
    l, r = list(map(int, input().split()))
    if l > left:
        left = l
    if r < right:
        right = r
    if left > right:
        print((0))
        quit()
print((right - left + 1))

import sys

n, m, *lst = list(map(int, sys.stdin.read().split()))
l = max(lst[::2])
r = min(lst[1::2])
if l > r:
    print((0))
else:
    print((r - l + 1))

-n, m = list(map(int, input().split())) -left, right = 1, n -for _ in range(m): -    l, r = list(map(int, input().split())) -    if l > left: -        left = l -    if r < right: -        right = r -    if left > right: -        print((0)) -        quit() -print((right - left + 1)) +import sys + +n, m, *lst = list(map(int, sys.stdin.read().split())) +l = max(lst[::2]) +r = min(lst[1::2]) +if l > r: +    print((0)) +else: +    print((r - l + 1))