program prison
  implicit none
  integer :: n, m, l, r, i, p = 1, q = 1e9
  read(*,*) n, m
  do i = 1, m
    read(*,*) l, r
    p = max(p,l)
    q = min(q,r)
  end do
  write(*,'(i0)') max(q-p+1,0)
end program prison