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

L = []

R = []

for i in range(M):

    x1, y1 = [int(i) for i in input().split()]

    L.append(x1)

    R.append(y1)



high=N

low=0



ans = [True for i in range(N)]

for i in range(M):

    for c,k in enumerate(range(L[i]-2, low-1, -1)):

        if(low < k):

            low=k

        ans[k]=False





    for c,j in enumerate(range(R[i],high)):

        if(high > j):

            high=j

        ans[j]=False





print((ans.count(True)))





def myAnswer(N,M,L,R) -> int:

   total = 0

   MAXL=max(L)

   MINR =min(R)

   for i in range(1,N+1):

      if(MAXL<= i and MINR >= i):

         total += 1

   return total





def modelAnswer():

   tmp=1

def main():

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

   L =[]

   R = []

   for _ in range(M):

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

      L.append(l)

      R.append(r)

   print((myAnswer(N,M,L[:],R[:])))

   



if __name__ == '__main__':

   main()
N, M = list(map(int, input().split()))
L = []
R = []
for i in range(M):
    x1, y1 = [int(i) for i in input().split()]
    L.append(x1)
    R.append(y1)
high = N
low = 0
ans = [True for i in range(N)]
for i in range(M):
    for c, k in enumerate(range(L[i] - 2, low - 1, -1)):
        if low < k:
            low = k
        ans[k] = False
    for c, j in enumerate(range(R[i], high)):
        if high > j:
            high = j
        ans[j] = False
print((ans.count(True)))

def myAnswer(N, M, L, R) -> int:
    total = 0
    MAXL = max(L)
    MINR = min(R)
    for i in range(1, N + 1):
        if MAXL <= i and MINR >= i:
            total += 1
    return total


def modelAnswer():
    tmp = 1


def main():
    N, M = list(map(int, input().split()))
    L = []
    R = []
    for _ in range(M):
        l, r = list(map(int, input().split()))
        L.append(l)
        R.append(r)
    print((myAnswer(N, M, L[:], R[:])))


if __name__ == "__main__":
    main()

-N, M = list(map(int, input().split())) -L = [] -R = [] -for i in range(M): -    x1, y1 = [int(i) for i in input().split()] -    L.append(x1) -    R.append(y1) -high = N -low = 0 -ans = [True for i in range(N)] -for i in range(M): -    for c, k in enumerate(range(L[i] - 2, low - 1, -1)): -        if low < k: -            low = k -        ans[k] = False -    for c, j in enumerate(range(R[i], high)): -        if high > j: -            high = j -        ans[j] = False -print((ans.count(True))) +def myAnswer(N, M, L, R) -> int: +    total = 0 +    MAXL = max(L) +    MINR = min(R) +    for i in range(1, N + 1): +        if MAXL <= i and MINR >= i: +            total += 1 +    return total + + +def modelAnswer(): +    tmp = 1 + + +def main(): +    N, M = list(map(int, input().split())) +    L = [] +    R = [] +    for _ in range(M): +        l, r = list(map(int, input().split())) +        L.append(l) +        R.append(r) +    print((myAnswer(N, M, L[:], R[:]))) + + +if __name__ == "__main__": +    main()