program answer
  implicit none
  integer :: i, n, ans
  integer, allocatable :: p(:)
  read(*,*) n
  allocate(p(n))
  read(*,*) p

  ans=0

  do i = 2, n-1
     if(max(p(i-1),p(i),p(i+1))/=p(i).and.min(p(i-1),p(i),p(i+1))/=p(i)) then
        ans=ans+1
     end if
  end do

  write(*,*) ans
  stop
 end program answer
  