program bbb

implicit none
integer :: n, i, co
integer, allocatable, dimension(:) :: p

read*, n
allocate(p(n))
read*, p

co=0

do i=2,n-1
if((p(i)<p(i-1)).and.(p(i)>p(i+1))) then
co=co+1
else if((p(i)>p(i-1)).and.(p(i)<p(i+1))) then
co=co+1
end if
end do

write(*,'(i0)') co

end program