# coding: utf-8 n = int(input()) a = list(map(int, input().split(" "))) res = 0 for i in range(n-2): k = a[i:i+3] if not(k[0] == k[1] or k[1] == k[2] or k[2] == k[0] or k[1] == sorted(k)[1]): res += 1 print(res)