import java.util.*

fun main(args: Array<String>) {
    val argList = Scanner(System.`in`)


    val n = argList.nextLine().toInt()
    val p = argList.nextLine().split(" ").map { it.toInt() }

    val executor = OrdinaryNumber()
    val result = executor.execute(n, p)
    println(result)
}

class OrdinaryNumber {
    fun execute(n: Int, p: List<Int>): Int {
        var count = 0
        val maxIndex = n - 1

        val beginIndex = 1
        val beforeEndIndex = maxIndex - 1
        for (i in beginIndex..beforeEndIndex) {
            val targetList = listOf(p[i - 1], p[i], p[i + 1])
            val sorted = targetList.sorted()

            if (p[i] == sorted[1]) {
                count++
            }
        }

        return count
    }
}