fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val pList = readLine()!!.split(" ").map { it.toInt() }

    var sum = 0
    for (i in 1 until n-1) {
        val prev = pList[i-1]
        val curr = pList[i]
        val next = pList[i+1]

        val list = mutableListOf(prev, curr, next)
        list.sort()
        if (list[1] == curr) sum++
    }

    println(sum)
}
