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