import java.util.Scanner

object Main {

  def solve(sc: Scanner): String = {
    val n = sc.nextInt()
    val p = Vector.fill(n)(sc.nextInt())
    debug(n, p)

    var count = 0
    for (i <- 2 until n) {
      val t = p(i - 1)
      if (t == Array(p(i - 2), t, p(i)).sorted.drop(1).head) count += 1
    }
    count.toString
  }

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val writer = new java.io.PrintWriter(System.out)
    writer.println(solve(sc))
    writer.flush()
  }

  private def debug(x: Any): Unit = {
    if (System.getenv("LOCAL_DEBUG") != null) println(x)
  }
}
