
object Main extends App {
  import scala.io.StdIn._

  val n = readInt()
  val perm = readLine.trim.split(' ').map(_.toInt)
  println(
    (1 until n - 1).count(i => perm(i) < math.max(perm(i + 1), perm(i - 1)) && perm(i) > math.min(perm(i + 1), perm(i - 1)))
  )
}