'use strict'
function main(input) {
    const tmp = input.split('\n');
    const n = parseInt(tmp[0], 10);
    const p = tmp[1].split(' ').map((t) => parseInt(t, 10));

    let count = 0;
    for (let start = 0; start + 2 < n; start++) {

        const numbers = [p[start], p[start + 1], p[start + 2]];
        const sortedNumbers = numbers.slice().sort((num1, num2) => num1 - num2);

        if (numbers[1] === sortedNumbers[1]) {
            count++;
        }
    }
    console.log(count);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));