def main():
    n, m = map(int, input().split())
    l_lst = [0 for _ in range(m)]
    r_lst = [0 for _ in range(m)]

    for i in range(m):
        l, r = map(int, input().split())
        l_lst[i] = l
        r_lst[i] = r

    left = max(l_lst)
    right = min(r_lst)

    if right - left < 0:
        print(0)
    else:
        print(right - left + 1)


if __name__ == "__main__":
    main() def main():
    n, m = map(int, input().split())
    l_lst = [0 for _ in range(m)]
    r_lst = [0 for _ in range(m)]

    for i in range(m):
        l, r = map(int, input().split())
        l_lst[i] = l
        r_lst[i] = r

    left = max(l_lst)
    right = min(r_lst)

    if right - left < 0:
        print(0)
    else:
        print(right - left + 1) main n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m 0 for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) 0 l_lst = [0 for _ in range(m)] l_lst [0 for _ in range(m)] 0 for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) 0 r_lst = [0 for _ in range(m)] r_lst [0 for _ in range(m)] for i in range(m):
        l, r = map(int, input().split())
        l_lst[i] = l
        r_lst[i] = r

     i range(m) range m l, r = map(int, input().split()) l map(int, input().split()) map int input().split() ().split () input split r l_lst[i] = l l_lst[i] l_lst i l r_lst[i] = r r_lst[i] r_lst i r left = max(l_lst) left max(l_lst) max l_lst right = min(r_lst) right min(r_lst) min r_lst if right - left < 0:
        print(0)
    else:
        print(right - left + 1) right - left < 0 right - left right left 0 print(0) print 0 print(right - left + 1) print right - left + 1 right - left right left 1 if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    n, m = map(int, input().split())
    l_lst = [0 for _ in range(m)]
    r_lst = [0 for _ in range(m)]

    for i in range(m):
        l, r = map(int, input().split())
        l_lst[i] = l
        r_lst[i] = r

    left = max(l_lst)
    right = min(r_lst)

    if right - left < 0:
        print(0)
    else:
        print(right - left + 1) def main():
    n, m = map(int, input().split())
    l_lst = [0 for _ in range(m)]
    r_lst = [0 for _ in range(m)]

    for i in range(m):
        l, r = map(int, input().split())
        l_lst[i] = l
        r_lst[i] = r

    left = max(l_lst)
    right = min(r_lst)

    if right - left < 0:
        print(0)
    else:
        print(right - left + 1) main
def main():
    n, m = map(int, input().split())
    l_lst = [0 for _ in range(m)]
    r_lst = [0 for _ in range(m)]

    for i in range(m):
        l, r = map(int, input().split())
        l_lst[i] = l
        r_lst[i] = r

    left = max(l_lst)
    right = min(r_lst)

    if right - left < 0:
        print(0)
    else:
        print(right - left + 1)


if __name__ == "__main__":
    main()
