
function Main(input) {
    var N = parseInt(input[0], 10);
    var P = input.slice(1).map(w => parseInt(w, 10));

    var result = 0;

    for (var i = 1; i < N - 1; i++) {
        if (P[i - 1] > P[i] && P[i] > P[i + 1]) {
            result++;
        } else if (P[i - 1] < P[i] && P[i] < P[i + 1]) {
            result++;
        }
    }
    console.log(result);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));