N, M = [int(i) for i in input().strip().split()]

L = [0] * M

R = [0] * M

for i in range(M):

    L[i], R[i] = [int(i) for i in input().strip().split()]



LL, RR = L[0], R[0]

is_zero = False

for i in range(1, M):

    if RR < L[i]:

        is_zero = True

        break

    elif LL <= L[i] <= RR:

        LL = max(LL, L[i])

        RR = min(RR, R[i])

    elif L[i] < LL <= R[i]:

        RR = min(RR, R[i])

    else:

        is_zero = True

        break



if is_zero:

    print((0))

else:

    print((RR - LL + 1))

import sys



input = sys.stdin.readline





def main():

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

    L = [None] * M

    R = [None] * M

    for i in range(M):

        L[i], R[i] = list(map(int, input().split()))



    L_max = max(L)

    R_min = min(R)

    if L_max > R_min:

        print((0))

    else:

        print((R_min - L_max + 1))





if __name__ == "__main__":

    main()

N, M = [int(i) for i in input().strip().split()]
L = [0] * M
R = [0] * M
for i in range(M):
    L[i], R[i] = [int(i) for i in input().strip().split()]
LL, RR = L[0], R[0]
is_zero = False
for i in range(1, M):
    if RR < L[i]:
        is_zero = True
        break
    elif LL <= L[i] <= RR:
        LL = max(LL, L[i])
        RR = min(RR, R[i])
    elif L[i] < LL <= R[i]:
        RR = min(RR, R[i])
    else:
        is_zero = True
        break
if is_zero:
    print((0))
else:
    print((RR - LL + 1))

import sys

input = sys.stdin.readline


def main():
    N, M = list(map(int, input().split()))
    L = [None] * M
    R = [None] * M
    for i in range(M):
        L[i], R[i] = list(map(int, input().split()))
    L_max = max(L)
    R_min = min(R)
    if L_max > R_min:
        print((0))
    else:
        print((R_min - L_max + 1))


if __name__ == "__main__":
    main()

-N, M = [int(i) for i in input().strip().split()] -L = [0] * M -R = [0] * M -for i in range(M): -    L[i], R[i] = [int(i) for i in input().strip().split()] -LL, RR = L[0], R[0] -is_zero = False -for i in range(1, M): -    if RR < L[i]: -        is_zero = True -        break -    elif LL <= L[i] <= RR: -        LL = max(LL, L[i]) -        RR = min(RR, R[i]) -    elif L[i] < LL <= R[i]: -        RR = min(RR, R[i]) +import sys + +input = sys.stdin.readline + + +def main(): +    N, M = list(map(int, input().split())) +    L = [None] * M +    R = [None] * M +    for i in range(M): +        L[i], R[i] = list(map(int, input().split())) +    L_max = max(L) +    R_min = min(R) +    if L_max > R_min: +        print((0)) -        is_zero = True -        break -if is_zero: -    print((0)) -else: -    print((RR - LL + 1)) +        print((R_min - L_max + 1)) + + +if __name__ == "__main__": +    main()