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



left = 1

right = N



for _ in range(M):

    l, r = list(map(int, input().split()))



    if left < l:

        left = l

    if right > r:

        right = r



ans = right - left



print((ans + 1 if ans >= 0 else 0))

def main():

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



    left = 1

    right = N



    for _ in range(M):

        l, r = list(map(int, input().split()))



        if left < l:

            left = l

        if right > r:

            right = r



    ans = right - left



    print((ans + 1 if ans >= 0 else 0))





main()

N, M = list(map(int, input().split()))
left = 1
right = N
for _ in range(M):
    l, r = list(map(int, input().split()))
    if left < l:
        left = l
    if right > r:
        right = r
ans = right - left
print((ans + 1 if ans >= 0 else 0))

def main():
    N, M = list(map(int, input().split()))
    left = 1
    right = N
    for _ in range(M):
        l, r = list(map(int, input().split()))
        if left < l:
            left = l
        if right > r:
            right = r
    ans = right - left
    print((ans + 1 if ans >= 0 else 0))


main()

-N, M = list(map(int, input().split())) -left = 1 -right = N -for _ in range(M): -    l, r = list(map(int, input().split())) -    if left < l: -        left = l -    if right > r: -        right = r -ans = right - left -print((ans + 1 if ans >= 0 else 0)) +def main(): +    N, M = list(map(int, input().split())) +    left = 1 +    right = N +    for _ in range(M): +        l, r = list(map(int, input().split())) +        if left < l: +            left = l +        if right > r: +            right = r +    ans = right - left +    print((ans + 1 if ans >= 0 else 0)) + + +main()