function main(input) {
    var n = input.split(/\n/)[0] / 1;
    var l2 = input.split(/\n/)[1];
    var array = l2.split(/\s/);
    for (var i = 0; i < array.length; i++) {
        array[i] /= 1;
    }
    var result = 0;
    for (var j = 0; j < array.length - 2; j++) {
        var three = [array[j], array[j + 1], array[j + 2]];
        var max = Math.max.apply(0, three);
        var min = Math.min.apply(0, three);
        if (three[1] != max && three[1] != min) {
            result++;
        }
    }
    console.log(result);
}

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