program prison
 integer N, M, i, j, res
 integer X(10**5)
 integer,allocatable,dimension(:) :: A
 integer,allocatable,dimension(:) :: B
  do 10 i=1,10**5
  X(i) = 0
  10 continue
  res = 0
 read(*,*) N, M
 allocate(A(M))
 allocate(B(M))
  do 100 i=1,M
  read(*,*) A(M), B(M)
   do 200 j=A(M), B(M)
   X(j) = X(j) +1
   200 continue
  100 continue
 do 1000 i=1, 10**5
  if (X(i).eq.M) then
  res = res + 1
  end if
 1000 continue
 write(*,*) res
end program