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