program tr
  implicit none
  integer ::i,j,n
  integer,allocatable ::p(:)

  read(*,*) n
  allocate(p(n))
  read(*,*) p
  j=0
  do i=2,n-1
     if((p(i).lt.max(p(i-1),p(i+1))).and.(p(i).gt.min(p(i-1),p(i+1))))then
        j=j+1
     endif
  enddo

  write(*,'(i0)') j
end program tr