import java.util.*
import java.math.*

fun main(args: Array<String>) {
//    var (N,L) = readLine()!!.split(" ").map { it.toInt() }
    var N = readLine()!!.toInt()
//    val S = readLine()!!.toInt()
    val P = readLine()!!.split(" ").map { it.toInt() }.toIntArray()

    var ans = 0
    for (i in 1 until N-1) {
        var p = arrayOf(P[i-1],P[i],P[i+1])
        p.sort()
        if (P[i] == p[1]) ans++

    }

    println(ans)
}

