import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n, m = MI()
    l, r = MI()
    for _ in range(m-1):
        li, ri = MI()
        l = max(l, li)
        r = min(r, ri)
    ans = max(0, r-l+1)
    print(ans)

if __name__ == '__main__':
    main() import sys sys def I(): return int(sys.stdin.readline()) I def MI(): return map(int, sys.stdin.readline().split()) MI def LI(): return list(map(int, sys.stdin.readline().split())) LI def main():
    n, m = MI()
    l, r = MI()
    for _ in range(m-1):
        li, ri = MI()
        l = max(l, li)
        r = min(r, ri)
    ans = max(0, r-l+1)
    print(ans) main n, m = MI() n MI() MI m l, r = MI() l MI() MI r for _ in range(m-1):
        li, ri = MI()
        l = max(l, li)
        r = min(r, ri)
     _ range(m-1) range m-1 m 1 li, ri = MI() li MI() MI ri l = max(l, li) l max(l, li) max l li r = min(r, ri) r min(r, ri) min r ri ans = max(0, r-l+1) ans max(0, r-l+1) max 0 r-l+1 r-l r l 1 print(ans) print ans if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    n, m = MI()
    l, r = MI()
    for _ in range(m-1):
        li, ri = MI()
        l = max(l, li)
        r = min(r, ri)
    ans = max(0, r-l+1)
    print(ans) def main():
    n, m = MI()
    l, r = MI()
    for _ in range(m-1):
        li, ri = MI()
        l = max(l, li)
        r = min(r, ri)
    ans = max(0, r-l+1)
    print(ans) main def MI(): return map(int, sys.stdin.readline().split()) def MI(): return map(int, sys.stdin.readline().split()) MI def LI(): return list(map(int, sys.stdin.readline().split())) def LI(): return list(map(int, sys.stdin.readline().split())) LI def I(): return int(sys.stdin.readline()) def I(): return int(sys.stdin.readline()) I
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n, m = MI()
    l, r = MI()
    for _ in range(m-1):
        li, ri = MI()
        l = max(l, li)
        r = min(r, ri)
    ans = max(0, r-l+1)
    print(ans)

if __name__ == '__main__':
    main()