const main = (inputs) => {
  var N = inputs[0]-0;
  var list = inputs[1].split(" ").map(v=>v-0);
  var ans = 0;
  for(var i=1;i<N-1;i++){
    var n = list[i];
    var srt = [list[i-1], list[i], list[i+1]].sort((a,b)=>a-b);
    if(n == srt[1]) ans++;
  }
  console.log(ans);
}

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