program ABC132B
    implicit none
    integer::n,i,ans=0
    integer,allocatable::P(:)
    read*,n
    allocate(P(n))
    read*,P
    do i=1,n-2
        if(P(i+1)/=maxval(P(i:i+2)).and.P(i+1)/=minval(P(i:i+2)))ans=ans+1
    end do
    print'(i0)',ans
end program ABC132B