N = input() A = map(int, raw_input().split()) res = 0 for i in range(N - 2): a = A[i] b = A[i + 1] c = A[i + 2] if (a == b or b == c): continue if (b < a or b > c): res += 1 print res