fun main(args: Array<String>) {
    val count = readLine()!!.toInt()
    val permutation = readLine()!!.split(" ").map { it.toInt() }
    var ans = 0

    for (n in 1 until count - 1) {
        when {
            (permutation[n - 1] < permutation[n]) && (permutation[n] < permutation[n + 1]) -> ans += 1
            (permutation[n - 1] > permutation[n]) && (permutation[n] > permutation[n + 1]) -> ans += 1
        }
    }
    print(ans)
}