c = gets.chomp
arr = gets.chomp.split(' ').map(&:to_i)
count = 0
(1..arr.size-2).each do |i|
  if (arr[i-1] > arr[i] && arr[i+1] < arr[i]) || (arr[i-1] < arr[i] && arr[i+1] > arr[i])
    count = count + 1
  end
end
puts count