n = gets.to_i
ps = gets.split.map(&:to_i)
count = 0
(0..n-3).each_with_index do |p,i|
    tmp = []
    tmp << ps[i]
    tmp << ps[i+1]
    tmp << ps[i+2]
    tmp.sort!
    count += 1 if tmp[1] == ps[i+1]
end
puts count
