program main
  implicit none
  integer :: n, m, i, j, l, r, left, right
  read (*, *) n, m
  left = 1  ! inclusive
  right = n
  do i = 1, m
    read (*, *) l, r
    left = max(left, l)
    right = min(right, r)
  end do
  write (*, "(i0)") max(0, right - left + 1)
end program main
