def main():
    n, m = map(int, input().split())
    lr_lst = [list(map(int, input().split())) for _ in range(m)]
    left = 0
    right = n + 1

    for i in range(m):
        if left < lr_lst[i][0]:
            left = lr_lst[i][0]
        if lr_lst[i][1] < right:
            right = lr_lst[i][1]

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


if __name__ == "__main__":
    main() def main():
    n, m = map(int, input().split())
    lr_lst = [list(map(int, input().split())) for _ in range(m)]
    left = 0
    right = n + 1

    for i in range(m):
        if left < lr_lst[i][0]:
            left = lr_lst[i][0]
        if lr_lst[i][1] < right:
            right = lr_lst[i][1]

    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 list(map(int, input().split())) for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split lr_lst = [list(map(int, input().split())) for _ in range(m)] lr_lst [list(map(int, input().split())) for _ in range(m)] left = 0 left 0 right = n + 1 right n + 1 n 1 for i in range(m):
        if left < lr_lst[i][0]:
            left = lr_lst[i][0]
        if lr_lst[i][1] < right:
            right = lr_lst[i][1]

     i range(m) range m if left < lr_lst[i][0]:
            left = lr_lst[i][0]
         left < lr_lst[i][0] left lr_lst[i][0] [i] lr_lst i 0 left = lr_lst[i][0] left lr_lst[i][0] [i] lr_lst i 0 if lr_lst[i][1] < right:
            right = lr_lst[i][1]

     lr_lst[i][1] < right lr_lst[i][1] [i] lr_lst i 1 right right = lr_lst[i][1] right lr_lst[i][1] [i] lr_lst i 1 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())
    lr_lst = [list(map(int, input().split())) for _ in range(m)]
    left = 0
    right = n + 1

    for i in range(m):
        if left < lr_lst[i][0]:
            left = lr_lst[i][0]
        if lr_lst[i][1] < right:
            right = lr_lst[i][1]

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

    for i in range(m):
        if left < lr_lst[i][0]:
            left = lr_lst[i][0]
        if lr_lst[i][1] < right:
            right = lr_lst[i][1]

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

    for i in range(m):
        if left < lr_lst[i][0]:
            left = lr_lst[i][0]
        if lr_lst[i][1] < right:
            right = lr_lst[i][1]

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


if __name__ == "__main__":
    main()
