n = STDIN.gets.to_i
p = STDIN.gets.chomp.split(" ")

count = 0
(n-2).times do |i|
  next if p[i] == p[i+1] && p[i+1] == p[i+2]

  sorted = [p[i], p[i+1], p[i+2]].sort
  count = count + 1 if sorted[0] < sorted[1]
end

puts count