function Main(input) {
  lines = input.split("\n")
  N = lines[0] * 1
  s = lines[1].split(" ").map(function(i) { return i * 1})
  cnt = 0
  for (var i = 0; i < s.length - 2; i++) {
    t = s.slice(i, i + 3)
    t = t.sort(function(a, b) { return a - b })
    if (t[1] == s[i+1]) {
      cnt++
    }
  }
  console.log(cnt)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
