function Main (input) {
  input = input.split("\n").map(inp => inp.split(" ").map(Number));
  var N = input[0];
  var A = input[1];
  var ans = 0;
  A.forEach((e, i, ar) => {
    if (i > 0 && i < N-1) {
      if ([ar[i-1], e, ar[i+1]].sort((a, b) => b > a)[1] == e) {
        ans++;
      }
    }
  });
  console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));