"use strict";
    
const main = arg => {
  	const N = arg.split("\n")[0]*1;
    const Nums = arg.split("\n")[1].split(" ");
  	let ans = 0;
  	for(let i = 0; i < N - 2;  i++){   
    	if(
          ((Nums[i]*1 < Nums[i+1]*1 ) && (Nums[i+1]*1 < Nums[i+2]*1))
          ||
          ((Nums[i]*1 > Nums[i+1]*1 ) && (Nums[i+1]*1 > Nums[i+2]*1))
        )
      	{
        	ans++;
        }
    }
  	console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
