fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val p = readLine()!!.split(" ")
    var c = 0
    for (i in 0..(n-3)){
        if (p[i + 1].toInt() > p[i].toInt() && p[i + 1].toInt() < p[i + 2].toInt() || p[i + 1].toInt() > p[i + 2].toInt() && p[i + 1].toInt() < p[i].toInt()) c++
    }
    print(c)
}
