def main(): N = int(input()) A = tuple(map(int, input().split())) ans = 0 for i in range(N - 2): max_ = max(A[i], A[i+1], A[i+2]) min_ = min(A[i], A[i+1], A[i+2]) if A[i+1] == min_ or A[i+1] == max_ and A[i] != A[i+2]: ans += 1 print(ans) main()