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

Lmax=1

Rmin=N

for i in range(M):

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

    Lmax=max(Lmax,L)

    Rmin=min(Rmin,R)

    

print((max(Rmin-Lmax+1,0)))
import sys

input = sys.stdin.readline



def I(): return int(eval(input()))

def MI(): return list(map(int, input().split()))

def LI(): return list(map(int, input().split()))



def main():

    mod=10**9+7

    N,M=MI()

    L=[0]*(N+1)

    for _ in range(M):

        l,r=MI()

        l-=1

        r-=1

        L[l]+=1

        L[r+1]-=1

        

    for i in range(N):

        L[i+1]+=L[i]

        

    ans=0

    

    for i in range(N):

        if L[i]>=M:

            ans+=1

            

    print(ans)

    



main()

N, M = list(map(int, input().split()))
Lmax = 1
Rmin = N
for i in range(M):
    L, R = list(map(int, input().split()))
    Lmax = max(Lmax, L)
    Rmin = min(Rmin, R)
print((max(Rmin - Lmax + 1, 0)))

import sys

input = sys.stdin.readline


def I():
    return int(eval(input()))


def MI():
    return list(map(int, input().split()))


def LI():
    return list(map(int, input().split()))


def main():
    mod = 10**9 + 7
    N, M = MI()
    L = [0] * (N + 1)
    for _ in range(M):
        l, r = MI()
        l -= 1
        r -= 1
        L[l] += 1
        L[r + 1] -= 1
    for i in range(N):
        L[i + 1] += L[i]
    ans = 0
    for i in range(N):
        if L[i] >= M:
            ans += 1
    print(ans)


main()

-N, M = list(map(int, input().split())) -Lmax = 1 -Rmin = N -for i in range(M): -    L, R = list(map(int, input().split())) -    Lmax = max(Lmax, L) -    Rmin = min(Rmin, R) -print((max(Rmin - Lmax + 1, 0))) +import sys + +input = sys.stdin.readline + + +def I(): +    return int(eval(input())) + + +def MI(): +    return list(map(int, input().split())) + + +def LI(): +    return list(map(int, input().split())) + + +def main(): +    mod = 10**9 + 7 +    N, M = MI() +    L = [0] * (N + 1) +    for _ in range(M): +        l, r = MI() +        l -= 1 +        r -= 1 +        L[l] += 1 +        L[r + 1] -= 1 +    for i in range(N): +        L[i + 1] += L[i] +    ans = 0 +    for i in range(N): +        if L[i] >= M: +            ans += 1 +    print(ans) + + +main()