function main(input){
  const args=input.split("\n");
  const n=parseInt(args[0], 10);
  const arr=args[1].split(" ").map((n) => parseInt(n, 10));
  console.log(arr);
  var ans=0;
  for(i=1; i<n-1; i++){
    if((arr[i-1]>=arr[i] && arr[i]>arr[i+1]) || (arr[i-1]<arr[i] && arr[i]<=arr[i+1])){
      ans++;
    }
  }
console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))