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