n = int(input()) a = list(map(int, input().split())) count = 0 for i in range(n - 2): x, y, z = a[i], a[i+1], a[i+2] if x == y or y == z or x == z: continue if y == max(x, y, z) or y == min(x, y, z): count += 1 print(count)