"use strict"
function main(arg) {
    arg = arg.trim().split("\n")[1].split(' ')
    const n = arg.length
    let ans = 0
    for (let i = 1; i < n - 1; i++) {
        let iP = arg[i - 1]
        let iC = arg[i]
        let iN = arg[i + 1]
        if (iP < iC && iC < iN) {
            ans++
            // console.log([iP,iC,iN])
        } else if (iN < iC && iC < iP) {
            ans++
        }
    }
    console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));