N=int(input()) A = list(map(int,input().split())) ANS=0 for i in range(1,N-1): if A[i-1]!=A[i] and A[i-1]!=A[i+1] and A[i]!=A[i+1]: if A[i-1]A[i]>A[i+1]: continue ANS+=1 print(ANS)