function Main(input) {
	input = input.split("\n");
	var arr = input[1].split(" ").map(Number);
	var sum = 0;
	for(var i=1;i<arr.length-1;i++){
		if((arr[i-1]<arr[i]&&arr[i]<arr[i+1])||(arr[i-1]>arr[i]&&arr[i]>arr[i+1])){
			sum++;
		}
	}
	console.log(sum);
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());