import sys

stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


n, m = nm()
l, r = nm()
for i in range(m - 1):
    l_t, r_t = nm()
    l, r = max(l, l_t), min(r, r_t)
if r >= l:
    print(r - l + 1)
else:
    print(0) import sys sys stdin = sys.stdin stdin sys.stdin sys stdin def ns(): return stdin.readline().rstrip() ns def ni(): return int(stdin.readline().rstrip()) ni def nm(): return map(int, stdin.readline().split()) nm def nl(): return list(map(int, stdin.readline().split())) nl n, m = nm() n nm() nm m l, r = nm() l nm() nm r for i in range(m - 1):
    l_t, r_t = nm()
    l, r = max(l, l_t), min(r, r_t) i range(m - 1) range m - 1 m 1 l_t, r_t = nm() l_t nm() nm r_t l, r = max(l, l_t), min(r, r_t) l max(l, l_t) max l l_t r min(r, r_t) min r r_t if r >= l:
    print(r - l + 1)
else:
    print(0) r >= l r l print(r - l + 1) print r - l + 1 r - l r l 1 print(0) print 0 r = nm() nm() r r_t = nm() nm() r_t def ni(): return int(stdin.readline().rstrip()) def ni(): return int(stdin.readline().rstrip()) ni def ns(): return stdin.readline().rstrip() def ns(): return stdin.readline().rstrip() ns def nl(): return list(map(int, stdin.readline().split())) def nl(): return list(map(int, stdin.readline().split())) nl n, m = nm() nm() n l_t, r_t = nm() nm() l_t def nm(): return map(int, stdin.readline().split()) def nm(): return map(int, stdin.readline().split()) nm stdin = sys.stdin sys.stdin stdin m = nm() nm() m l, r = max(l, l_t), min(r, r_t) max(l, l_t) l r = max(l, l_t), min(r, r_t) min(r, r_t) r l, r = nm() nm() l
import sys

stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


n, m = nm()
l, r = nm()
for i in range(m - 1):
    l_t, r_t = nm()
    l, r = max(l, l_t), min(r, r_t)
if r >= l:
    print(r - l + 1)
else:
    print(0)
