
url = "https://atcoder.jp//contests/abc127/tasks/abc127_c"

def main():
    n, m = list(map(int, input().split()))
    l, r = 0, 999999
    for i in range(m):
        a,b = list(map(int, input().split()))
        l = a if a > l else l
        r = b if b < r else r
    ans = r - l
    print(ans + 1) if ans >= 0 else print(0)


if __name__ == '__main__':
    main() url = "https://atcoder.jp//contests/abc127/tasks/abc127_c" url "https://atcoder.jp//contests/abc127/tasks/abc127_c" def main():
    n, m = list(map(int, input().split()))
    l, r = 0, 999999
    for i in range(m):
        a,b = list(map(int, input().split()))
        l = a if a > l else l
        r = b if b < r else r
    ans = r - l
    print(ans + 1) if ans >= 0 else print(0) main n, m = list(map(int, input().split())) n list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split m l, r = 0, 999999 l 0 r 999999 for i in range(m):
        a,b = list(map(int, input().split()))
        l = a if a > l else l
        r = b if b < r else r
     i range(m) range m a,b = list(map(int, input().split())) a list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split b l = a if a > l else l l a if a > l else l a > l a l a l r = b if b < r else r r b if b < r else r b < r b r b r ans = r - l ans r - l r l print(ans + 1) if ans >= 0 else print(0) ans >= 0 ans 0 print(ans + 1) print ans + 1 ans 1 print(0) print 0 if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main url = "https://atcoder.jp//contests/abc127/tasks/abc127_c" "https://atcoder.jp//contests/abc127/tasks/abc127_c" url def main():
    n, m = list(map(int, input().split()))
    l, r = 0, 999999
    for i in range(m):
        a,b = list(map(int, input().split()))
        l = a if a > l else l
        r = b if b < r else r
    ans = r - l
    print(ans + 1) if ans >= 0 else print(0) def main():
    n, m = list(map(int, input().split()))
    l, r = 0, 999999
    for i in range(m):
        a,b = list(map(int, input().split()))
        l = a if a > l else l
        r = b if b < r else r
    ans = r - l
    print(ans + 1) if ans >= 0 else print(0) main

url = "https://atcoder.jp//contests/abc127/tasks/abc127_c"

def main():
    n, m = list(map(int, input().split()))
    l, r = 0, 999999
    for i in range(m):
        a,b = list(map(int, input().split()))
        l = a if a > l else l
        r = b if b < r else r
    ans = r - l
    print(ans + 1) if ans >= 0 else print(0)


if __name__ == '__main__':
    main()
