#少し修正 N = int(input()) k = list(map(int, input().split())) c = 0 for i,v in enumerate(k[1:-1],1): if len(set([k[i-1], v ,k[i+1]])) == 3: if k[i-1] > v < k[i+1] or k[i-1] < v > k[i+1]: c += 1 print(c)