program main
  implicit none
  integer :: n, i, res
  integer, allocatable :: p(:)
  read (*, *) n
  allocate (p(n))
  read (*, *) p(:)
  res = 0
  do i = 1, n - 2
    if ((p(i) < p(i + 1) .and. p(i + 1) < p(i + 2)) .or. (p(i) > p(i + 1) .and. p(i + 1) > p(i + 2))) res = res + 1
  end do
  write (*, "(i0)") res
end program main
