def isKadomatsu(a, b, c): l = [a, b, c] if len(l) != len(set(l)): return False sl = sorted(l) if sl[1] == a or sl[1] == c: return True else: return False N = input() K = list(map(int, input().split())) res = 0 for i, Ki in enumerate(K): if i == 0 or i == len(K) - 1: continue if isKadomatsu(K[i-1], K[i], K[i+1]): res += 1 print(res)