var count = 0;

function Main(input) {

	input = input.split("\n");
	
	var n = parseInt(input[0]);
	var p = input[1].split(" ");
	p = p.map(p => parseInt(p,10));
	
	for(var i = 0;i < n - 2;i++){
	    if(p[i] < p[i+1] && p[i+1] < p[i+2]){
	        count++;
	    }else if(p[i] > p[i+1] && p[i+1] > p[i+2]){
	        count++;
	    }
	}
	
    console.log(count);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));