n = gets.chomp.to_i
pn = gets.chomp.split(" ").map(&:to_i)

cnt = 0

for i in 1..n-2 do
    if pn[i-1] < pn[i] && pn[i] < pn[i+1]
        cnt += 1
    elsif pn[i-1] > pn[i] && pn[i] > pn[i+1]
        cnt += 1
    end
end

puts cnt