function Main(input) {
  lines = input.split("\n");
  numbers = lines[1].split(" ");
  count = 0;
  
  for(i=0; i<lines[0]-2; i++){
    max = Math.max(numbers[0], numbers[1], numbers[2]);
    min = Math.min(numbers[0], numbers[1], numbers[2]);
    if(numbers[1] != max && numbers[1] != min){
      count += 1;
    }
    numbers.splice(0,1);
  }
  console.log(count);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

