N=input();A=map(int,raw_input().split()) print sum((A[i]-A[i+1])*(A[i+1]-A[i+2])<0 and A[i]!=A[i+2]for i in range(N-2))