function main(input) {
	var inputSeparated = input.split('\n');
  	var a = inputSeparated[1].split(' ').map(i=>parseInt(i));
  	var checkTimes = a.length - 2;
  	var count = 0;
  	for(var i = 0;i<checkTimes;i++){
    	var threeNumbers = a.slice(i,i+3);
	     //   console.log(threeNumbers);
      	if(threeNumbers[0]<threeNumbers[1] && threeNumbers[1]<threeNumbers[2]){
			count ++; 
        }else if(threeNumbers[0]>threeNumbers[1] && threeNumbers[1]>threeNumbers[2]){
         	count ++; 
        }
    }
  console.log(count);

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