fun main(args: Array<String>) {
  val n = readLine()!!
  val p = readLine()!!.split(" ").map { it.toInt() }
  var count = 0
  (0..(p.size-3)).forEach {
    val p0 = p[it]
    val p1 = p[it + 1]
    val p2 = p[it + 2]
    if (p1 in p0..p2 || p1 in p2..p0) count++
  }
  println(count)
}