def solve()
  n = readline.to_i
  p = readline.split.map!(&:to_i)
  cnt = 0
  array = []
  for i in 1..n-2 do
    array.push(p[i-1], p[i], p[i+1])
    if array.max != p[i] && array.min != p[i] then
      cnt += 1
    end
    array = []
  end
  print(cnt)
end
solve()