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

count = 0
for j in 1..n-2
  if p[j-1]<p[j] && p[j]<p[j+1]
    count += 1
  elsif p[j-1]>p[j] && p[j]>p[j+1]
    count += 1
  else
    count += 0
  end
end
puts count

