fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val p = readLine()!!.split(" ").map { it.toInt() }
    var count = 0
    (0..(n  - 3)).forEach { i ->
        val one = p[i]
        val two = p[i + 1]
        val three = p[i + 2]

        if ((one < two && two < three) || three < two && two < one) {
            count++
        }
    }

    println(count)
}