temp=input().split()

N=int(temp[0])

M=int(temp[1])

Lmax=int(0)

Rmin=int(N-1)



for i in range(M):

  temp=list(map(int, input().split()))

  if Lmax<temp[0]-1:

    Lmax=temp[0]-1

    

  if Rmin>temp[1]-1:

    Rmin=temp[1]-1

    

if Rmin>=Lmax:

  print((Rmin-Lmax+1))

else:

  print((0))
import numpy as np



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



L=1

R=N



for i in range(M):

  temp=list(map(int, input().split()))

  

  if L<temp[0]:

    L=temp[0]

    

  if R>temp[1]:

    R=temp[1]

    

temp=int(R-L+1)

if temp>0:

  print(temp)

else:

  print((0))
temp = input().split()
N = int(temp[0])
M = int(temp[1])
Lmax = int(0)
Rmin = int(N - 1)
for i in range(M):
    temp = list(map(int, input().split()))
    if Lmax < temp[0] - 1:
        Lmax = temp[0] - 1
    if Rmin > temp[1] - 1:
        Rmin = temp[1] - 1
if Rmin >= Lmax:
    print((Rmin - Lmax + 1))
else:
    print((0))

import numpy as np

N, M = list(map(int, input().split()))
L = 1
R = N
for i in range(M):
    temp = list(map(int, input().split()))
    if L < temp[0]:
        L = temp[0]
    if R > temp[1]:
        R = temp[1]
temp = int(R - L + 1)
if temp > 0:
    print(temp)
else:
    print((0))

-temp = input().split() -N = int(temp[0]) -M = int(temp[1]) -Lmax = int(0) -Rmin = int(N - 1) +import numpy as np + +N, M = list(map(int, input().split())) +L = 1 +R = N -    if Lmax < temp[0] - 1: -        Lmax = temp[0] - 1 -    if Rmin > temp[1] - 1: -        Rmin = temp[1] - 1 -if Rmin >= Lmax: -    print((Rmin - Lmax + 1)) +    if L < temp[0]: +        L = temp[0] +    if R > temp[1]: +        R = temp[1] +temp = int(R - L + 1) +if temp > 0: +    print(temp)