n = int(input()) a = list(map(int, input().split())) x = 0 for i in range(n-2): b = a[i+2] c = a[i+1] d = a[i] if b != c and c != d and b != d and (b < c > d or b > c < d): x += 1 print(x)