n = int(input()) l = list(map(int,input().split())) s = 0 for i in range(n-2): if l[0] != l[2] and ((l[0] < l[1] and l[1] > l[2]) or (l[0] > l[1] and l[1] < l[2])): s += 1 l.pop(0) print(s)