program main
implicit none
character*16 :: a
integer :: n,i,j,x
integer,allocatable :: p(:)

read(*,*)n
allocate(p(n))
read(*, *)(p(i), i = 1,n)

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

write(*,*) x

end program main