program main
 implicit none
 integer*8 n,i,ans
 integer*8, allocatable::p(:)
 read(*,*) n
 allocate (p(1:n))
 ans = 0
 read(*,*) p
 do i=1,n-2
  if(p(i)<=p(i+1) .and. p(i+1)<=p(i+2))then
   ans = ans + 1
  else if(p(i)>=p(i+1) .and. p(i+1)>=p(i+2))then
   ans = ans + 1
  end if
 end do
 write(*,*) ans
end program main