n = gets.chomp.to_i
s = gets.chomp.split(" ").map(&:to_i)
count = 0
(1..n-2).each do |i|
    if s[i] > s[i-1] && s[i] <= s[i+1]
        count += 1
    elsif s[i] <= s[i-1] && s[i] > s[i+1]
        count += 1
    end
end
puts count