n, m = list(map(int, input().split()))



l, r = [], []

for _ in range(m):

    ll, rr = list(map(int, input().split()))

    l.append(ll)

    r.append(rr)



print((max(0, min(r) - max(l) + 1)))

def main():

    import sys



    input = sys.stdin.readline



    N, M = list(map(int, input().split()))



    L, R = 1, N

    for _ in range(M):

        left, right = list(map(int, input().split()))

        L = max(L, left)

        R = min(R, right)

    ans = max(0, R - L + 1)

    print(ans)





if __name__ == '__main__':

    main()



# import sys

#

# sys.setrecursionlimit(10 ** 7)

#

# input = sys.stdin.readline

# rstrip()

# int(input())

# map(int, input().split())

n, m = list(map(int, input().split()))
l, r = [], []
for _ in range(m):
    ll, rr = list(map(int, input().split()))
    l.append(ll)
    r.append(rr)
print((max(0, min(r) - max(l) + 1)))

def main():
    import sys

    input = sys.stdin.readline
    N, M = list(map(int, input().split()))
    L, R = 1, N
    for _ in range(M):
        left, right = list(map(int, input().split()))
        L = max(L, left)
        R = min(R, right)
    ans = max(0, R - L + 1)
    print(ans)


if __name__ == "__main__":
    main()
# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())

-n, m = list(map(int, input().split())) -l, r = [], [] -for _ in range(m): -    ll, rr = list(map(int, input().split())) -    l.append(ll) -    r.append(rr) -print((max(0, min(r) - max(l) + 1))) +def main(): +    import sys + +    input = sys.stdin.readline +    N, M = list(map(int, input().split())) +    L, R = 1, N +    for _ in range(M): +        left, right = list(map(int, input().split())) +        L = max(L, left) +        R = min(R, right) +    ans = max(0, R - L + 1) +    print(ans) + + +if __name__ == "__main__": +    main() +# import sys +# +# sys.setrecursionlimit(10 ** 7) +# +# input = sys.stdin.readline +# rstrip() +# int(input()) +# map(int, input().split())