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

nmin = 1

nmax = N

for _ in range(M):

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

    nmin = max(nmin, l)

    nmax = min(nmax, r)

if nmin > nmax:

    print((0))

else:

    print((nmax - nmin + 1))
import sys

import numpy as np



def main(lines):

  N, M = np.fromstring(lines[0], dtype=int, sep=" ")

  a = np.fromstring(''.join(lines[1:]), dtype=int, sep=" ").reshape((2, M), order='F')

  

  lmax = a[0].max()

  rmin = a[1].min()

  if lmax > rmin:

    print((0))

  else:

    print((rmin - lmax + 1))



lines = sys.stdin.readlines()

main(lines)
N, M = list(map(int, input().split()))
nmin = 1
nmax = N
for _ in range(M):
    l, r = list(map(int, input().split()))
    nmin = max(nmin, l)
    nmax = min(nmax, r)
if nmin > nmax:
    print((0))
else:
    print((nmax - nmin + 1))

import sys
import numpy as np


def main(lines):
    N, M = np.fromstring(lines[0], dtype=int, sep=" ")
    a = np.fromstring("".join(lines[1:]), dtype=int, sep=" ").reshape((2, M), order="F")
    lmax = a[0].max()
    rmin = a[1].min()
    if lmax > rmin:
        print((0))
    else:
        print((rmin - lmax + 1))


lines = sys.stdin.readlines()
main(lines)

-N, M = list(map(int, input().split())) -nmin = 1 -nmax = N -for _ in range(M): -    l, r = list(map(int, input().split())) -    nmin = max(nmin, l) -    nmax = min(nmax, r) -if nmin > nmax: -    print((0)) -else: -    print((nmax - nmin + 1)) +import sys +import numpy as np + + +def main(lines): +    N, M = np.fromstring(lines[0], dtype=int, sep=" ") +    a = np.fromstring("".join(lines[1:]), dtype=int, sep=" ").reshape((2, M), order="F") +    lmax = a[0].max() +    rmin = a[1].min() +    if lmax > rmin: +        print((0)) +    else: +        print((rmin - lmax + 1)) + + +lines = sys.stdin.readlines() +main(lines)