function Main(input){
  input = input.split("\n");
  inputStr = input[0].split(" ");
  var N = Number.parseInt(inputStr[0]);
  var P = input[1].split(" ");
  var count = 0;
  var max = 0;
  var min = 0;
  
  for (var i = 1; i < N - 1 ; i++ ){
  	max = Math.max(Number.parseInt(P[i-1]),Number.parseInt(P[i]),Number.parseInt(P[i+1]));	
  	min = Math.min(Number.parseInt(P[i-1]),Number.parseInt(P[i]),Number.parseInt(P[i+1]));	

    if (Number.parseInt(P[i]) != max && Number.parseInt(P[i]) != min ){
      count += 1;
    }
  }
  console.log(count);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

