def abc127c():
    n, m = map(int, input().split())
    ls = []
    rs = []
    for _ in range(m):
        l, r = map(int, input().split())
        ls.append(l)
        rs.append(r)
    ans = max(min(rs)-max(ls)+1, 0)
    print(ans)
abc127c() def abc127c():
    n, m = map(int, input().split())
    ls = []
    rs = []
    for _ in range(m):
        l, r = map(int, input().split())
        ls.append(l)
        rs.append(r)
    ans = max(min(rs)-max(ls)+1, 0)
    print(ans) abc127c n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m ls = [] ls [] rs = [] rs [] for _ in range(m):
        l, r = map(int, input().split())
        ls.append(l)
        rs.append(r)
     _ range(m) range m l, r = map(int, input().split()) l map(int, input().split()) map int input().split() ().split () input split r ls.append(l) ls.append ls append l rs.append(r) rs.append rs append r ans = max(min(rs)-max(ls)+1, 0) ans max(min(rs)-max(ls)+1, 0) max min(rs)-max(ls)+1 min(rs)-max(ls) min(rs) min rs max(ls) max ls 1 0 print(ans) print ans abc127c() abc127c def abc127c():
    n, m = map(int, input().split())
    ls = []
    rs = []
    for _ in range(m):
        l, r = map(int, input().split())
        ls.append(l)
        rs.append(r)
    ans = max(min(rs)-max(ls)+1, 0)
    print(ans) def abc127c():
    n, m = map(int, input().split())
    ls = []
    rs = []
    for _ in range(m):
        l, r = map(int, input().split())
        ls.append(l)
        rs.append(r)
    ans = max(min(rs)-max(ls)+1, 0)
    print(ans) abc127c
def abc127c():
    n, m = map(int, input().split())
    ls = []
    rs = []
    for _ in range(m):
        l, r = map(int, input().split())
        ls.append(l)
        rs.append(r)
    ans = max(min(rs)-max(ls)+1, 0)
    print(ans)
abc127c()