import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n, m = inintm()

min_id = 10**5+1
max_id = 0

for _ in range(m):
    l, r = inintm()
    min_id = min(min_id, r)
    max_id = max(max_id, l)

print(max(0, min_id-max_id+1)) import sys sys inint = lambda: int(sys.stdin.readline()) inint lambda: int(sys.stdin.readline()) int(sys.stdin.readline()) int sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline inintm = lambda: map(int, sys.stdin.readline().split()) inintm lambda: map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) map int sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split inintl = lambda: list(inintm()) inintl lambda: list(inintm()) list(inintm()) list inintm() inintm instrm = lambda: map(str, sys.stdin.readline().split()) instrm lambda: map(str, sys.stdin.readline().split()) map(str, sys.stdin.readline().split()) map str sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split instrl = lambda: list(instrm()) instrl lambda: list(instrm()) list(instrm()) list instrm() instrm n, m = inintm() n inintm() inintm m min_id = 10**5+1 min_id 10**5+1 10**5 10 5 1 max_id = 0 max_id 0 for _ in range(m):
    l, r = inintm()
    min_id = min(min_id, r)
    max_id = max(max_id, l) _ range(m) range m l, r = inintm() l inintm() inintm r min_id = min(min_id, r) min_id min(min_id, r) min min_id r max_id = max(max_id, l) max_id max(max_id, l) max max_id l print(max(0, min_id-max_id+1)) print max(0, min_id-max_id+1) max 0 min_id-max_id+1 min_id-max_id min_id max_id 1 n, m = inintm() inintm() n m = inintm() inintm() m min_id = 10**5+1 10**5+1 min_id instrl = lambda: list(instrm()) lambda: list(instrm()) instrl max_id = 0 0 max_id r = inintm() inintm() r inint = lambda: int(sys.stdin.readline()) lambda: int(sys.stdin.readline()) inint instrm = lambda: map(str, sys.stdin.readline().split()) lambda: map(str, sys.stdin.readline().split()) instrm max_id = max(max_id, l) max(max_id, l) max_id inintm = lambda: map(int, sys.stdin.readline().split()) lambda: map(int, sys.stdin.readline().split()) inintm inintl = lambda: list(inintm()) lambda: list(inintm()) inintl min_id = min(min_id, r) min(min_id, r) min_id l, r = inintm() inintm() l
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n, m = inintm()

min_id = 10**5+1
max_id = 0

for _ in range(m):
    l, r = inintm()
    min_id = min(min_id, r)
    max_id = max(max_id, l)

print(max(0, min_id-max_id+1))