import itertools input() ary = list(map(int, input().split())) ans = 0 for i in range(len(ary) - 2): tmp = ary[i:i + 3] dup = False for j in itertools.combinations(tmp, 2): if(j[0] == j[1]): sup = True if(not dup): tmp[tmp.index(max(tmp))] = 0 if(tmp.index(max(tmp)) == 0 or tmp.index(max(tmp)) == 1): ans += 1 print(ans)