function main(input) {
    input = input.split("\n");
    var n = parseInt(input[0]);
    var Ps = input[1].split(" ").map((v) => parseInt(v, 10));

    var count = 0;
    for(var i = 1; Ps.length - 1 > i; i++) {
        if (Math.min(Ps[i - 1], Ps[i], Ps[i + 1]) >= Ps[i]) {
            continue;
        }
        if (max = Math.max(Ps[i - 1], Ps[i], Ps[i + 1]) <= Ps[i]) {
            continue;
        }

        count++;
    }

    console.log(count);
}

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