'use strict';(function(input){
  input=input.trim().split(/\n+/);
  const N=input[0]-0,
        p=input[1].split(/\s+/).map(x=>x-0));
  let ans=0;
  for(let i=1;i<N-1;i++){
    if(((p[i+1]-p[i])*(p[i]-p[i-1]))>0){
      ans++;
    }
  }
  console.log(ans);
})(require('fs').readFileSync('/dev/stdin','utf8'));