def solve():
    import sys
    n, m, *LR = map(int, sys.stdin.read().split())
    L = LR[::2]
    R = LR[1::2]
    l = max(L)
    r = min(R)
    print(max(0, r - l + 1))


solve() def solve():
    import sys
    n, m, *LR = map(int, sys.stdin.read().split())
    L = LR[::2]
    R = LR[1::2]
    l = max(L)
    r = min(R)
    print(max(0, r - l + 1)) solve import sys sys n, m, *LR = map(int, sys.stdin.read().split()) n map(int, sys.stdin.read().split()) map int sys.stdin.read().split() sys.stdin.read().split sys.stdin.read() sys.stdin.read sys.stdin sys stdin read split m *LR LR L = LR[::2] L LR[::2] LR ::2 2 R = LR[1::2] R LR[1::2] LR 1::2 1 2 l = max(L) l max(L) max L r = min(R) r min(R) min R print(max(0, r - l + 1)) print max(0, r - l + 1) max 0 r - l + 1 r - l r l 1 solve() solve def solve():
    import sys
    n, m, *LR = map(int, sys.stdin.read().split())
    L = LR[::2]
    R = LR[1::2]
    l = max(L)
    r = min(R)
    print(max(0, r - l + 1)) def solve():
    import sys
    n, m, *LR = map(int, sys.stdin.read().split())
    L = LR[::2]
    R = LR[1::2]
    l = max(L)
    r = min(R)
    print(max(0, r - l + 1)) solve
def solve():
    import sys
    n, m, *LR = map(int, sys.stdin.read().split())
    L = LR[::2]
    R = LR[1::2]
    l = max(L)
    r = min(R)
    print(max(0, r - l + 1))


solve()
