N = int(raw_input()) seq = map(int, raw_input().split()) ans = 0 for (a, b, c) in [(seq[i], seq[i+1], seq[i+2]) for i in range(N-2)]: if a == b or b == c or c == a: continue elif max(a, b, c) == b or min(a, b, c) == b: ans += 1 else: continue print ans