def main():
    x = list(map(int, input().split()))
    n = x[0]
    m = x[1]

    common_section = [1, n]

    for i in range(m):
        a = list(map(int, input().split()))
        if a[0] > common_section[0]:
            common_section[0] = a[0]
        if a[1] < common_section[1]:
            common_section[1] = a[1]

    answer = common_section[1] - common_section[0] + 1
    if answer < 0:
        answer = 0
    print(answer)


if __name__ == "__main__":
    main() def main():
    x = list(map(int, input().split()))
    n = x[0]
    m = x[1]

    common_section = [1, n]

    for i in range(m):
        a = list(map(int, input().split()))
        if a[0] > common_section[0]:
            common_section[0] = a[0]
        if a[1] < common_section[1]:
            common_section[1] = a[1]

    answer = common_section[1] - common_section[0] + 1
    if answer < 0:
        answer = 0
    print(answer) main x = list(map(int, input().split())) x list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split n = x[0] n x[0] x 0 m = x[1] m x[1] x 1 common_section = [1, n] common_section [1, n] 1 n for i in range(m):
        a = list(map(int, input().split()))
        if a[0] > common_section[0]:
            common_section[0] = a[0]
        if a[1] < common_section[1]:
            common_section[1] = a[1]

     i range(m) range m a = list(map(int, input().split())) a list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split if a[0] > common_section[0]:
            common_section[0] = a[0]
         a[0] > common_section[0] a[0] a 0 common_section[0] common_section 0 common_section[0] = a[0] common_section[0] common_section 0 a[0] a 0 if a[1] < common_section[1]:
            common_section[1] = a[1]

     a[1] < common_section[1] a[1] a 1 common_section[1] common_section 1 common_section[1] = a[1] common_section[1] common_section 1 a[1] a 1 answer = common_section[1] - common_section[0] + 1 answer common_section[1] - common_section[0] + 1 common_section[1] - common_section[0] common_section[1] common_section 1 common_section[0] common_section 0 1 if answer < 0:
        answer = 0
     answer < 0 answer 0 answer = 0 answer 0 print(answer) print answer if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    x = list(map(int, input().split()))
    n = x[0]
    m = x[1]

    common_section = [1, n]

    for i in range(m):
        a = list(map(int, input().split()))
        if a[0] > common_section[0]:
            common_section[0] = a[0]
        if a[1] < common_section[1]:
            common_section[1] = a[1]

    answer = common_section[1] - common_section[0] + 1
    if answer < 0:
        answer = 0
    print(answer) def main():
    x = list(map(int, input().split()))
    n = x[0]
    m = x[1]

    common_section = [1, n]

    for i in range(m):
        a = list(map(int, input().split()))
        if a[0] > common_section[0]:
            common_section[0] = a[0]
        if a[1] < common_section[1]:
            common_section[1] = a[1]

    answer = common_section[1] - common_section[0] + 1
    if answer < 0:
        answer = 0
    print(answer) main
def main():
    x = list(map(int, input().split()))
    n = x[0]
    m = x[1]

    common_section = [1, n]

    for i in range(m):
        a = list(map(int, input().split()))
        if a[0] > common_section[0]:
            common_section[0] = a[0]
        if a[1] < common_section[1]:
            common_section[1] = a[1]

    answer = common_section[1] - common_section[0] + 1
    if answer < 0:
        answer = 0
    print(answer)


if __name__ == "__main__":
    main()
