fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val ps = readLine()!!.split(" ").map { it.toInt() }
    var cnt = 0
    for (i in (1 until n - 1)) {
        if (ps[i] == arrayOf(ps[i-1], ps[i], ps[i+1]).sorted()[1]) cnt++
    }
    print(cnt)
}