const main = (inputs) => {
  var N = inputs[0].split("");
  var list = inputs[1].split(" ").map(v=>v-0);
  var ans = 0;
  for(var i=1;i<N-1;i++){
    if(list[i] > list[i-1] && list[i] < list[i+1]) ans++;
    else if(list[i] > list[i+1] && list[i] < list[i-1]) ans++;
  }
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));
