fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val p = readLine()!!.split(' ').map { s -> s.toLong() }
    var cnt = 0L
    (1..n-2).forEach{
        index ->
            cnt += if ((p[index-1] < p[index] && p[index] < p[index+1]) || (p[index+1] < p[index] && p[index] < p[index-1])) 1L else 0L 
    }
    println(cnt)
}