N=int(input()) L=list(map(int,input().split())) O=0 for i in range(N-2): A=L[i:i+3] if max(A)>A[0]>min(A) or max(A)>A[2]>min(A):O+=1 print(O)