N = int(input()) A = list(map(int, input().split())) def is_match(a, b, c) -> bool: if a == b or b == c or c == a: return False if a < b < c: return False if a > b > c: return False return True ans = 0 for i in range(N-2): a, b, c = A[i], A[i+1], A[i+2] if is_match(a, b, c): ans += 1 print(ans)