import scala.io.{StdIn => in}

object Main extends App {
  val n = in.readInt
  val p = in.readLine.split(" ").map(_.toInt)

  val table = Array.ofDim[Int](n+1)
  for(i <- 0 until n - 2) {
    val v = Seq(p(i), p(i+1), p(i+2)).sorted
    if(v(1) == p(i+1)) {
      table(p(i+1)) += 1
    }
  }

  val ans = table.count(_ > 0)
  println(ans)
}