def mapt(fn, *args):
    return tuple(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))


def main():
    n, m = Input()
    max_l = 0
    min_r = 1e6
    for i in range(m):
        l, r = Input()
        max_l = max(max_l, l)
        min_r = min(min_r, r)

    ans = min_r - max_l + 1
    ans = max(ans, 0)
    print(ans)

main() def mapt(fn, *args):
    return tuple(map(fn, *args)) mapt return tuple(map(fn, *args)) tuple(map(fn, *args)) tuple map(fn, *args) map fn *args args fn fn *args def Input():
    return mapt(int, input().split(" ")) Input return mapt(int, input().split(" ")) mapt(int, input().split(" ")) mapt int input().split(" ") ().split () input split " " def main():
    n, m = Input()
    max_l = 0
    min_r = 1e6
    for i in range(m):
        l, r = Input()
        max_l = max(max_l, l)
        min_r = min(min_r, r)

    ans = min_r - max_l + 1
    ans = max(ans, 0)
    print(ans) main n, m = Input() n Input() Input m max_l = 0 max_l 0 min_r = 1e6 min_r 1e6 for i in range(m):
        l, r = Input()
        max_l = max(max_l, l)
        min_r = min(min_r, r)

     i range(m) range m l, r = Input() l Input() Input r max_l = max(max_l, l) max_l max(max_l, l) max max_l l min_r = min(min_r, r) min_r min(min_r, r) min min_r r ans = min_r - max_l + 1 ans min_r - max_l + 1 min_r - max_l min_r max_l 1 ans = max(ans, 0) ans max(ans, 0) max ans 0 print(ans) print ans main() main def main():
    n, m = Input()
    max_l = 0
    min_r = 1e6
    for i in range(m):
        l, r = Input()
        max_l = max(max_l, l)
        min_r = min(min_r, r)

    ans = min_r - max_l + 1
    ans = max(ans, 0)
    print(ans) def main():
    n, m = Input()
    max_l = 0
    min_r = 1e6
    for i in range(m):
        l, r = Input()
        max_l = max(max_l, l)
        min_r = min(min_r, r)

    ans = min_r - max_l + 1
    ans = max(ans, 0)
    print(ans) main def Input():
    return mapt(int, input().split(" ")) def Input():
    return mapt(int, input().split(" ")) Input def mapt(fn, *args):
    return tuple(map(fn, *args)) def mapt(fn, *args):
    return tuple(map(fn, *args)) mapt
def mapt(fn, *args):
    return tuple(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))


def main():
    n, m = Input()
    max_l = 0
    min_r = 1e6
    for i in range(m):
        l, r = Input()
        max_l = max(max_l, l)
        min_r = min(min_r, r)

    ans = min_r - max_l + 1
    ans = max(ans, 0)
    print(ans)

main()