import scala.io.StdIn

object Main extends App {
  val n  = StdIn.readLine().toInt
  val p :Array[Int] = StdIn.readLine().split(" ").map(_.toInt)

  def solve(n: Int, p: Array[Int]): Int = {
    var v = 0
      (0 to (n - 3)).foreach {i =>

        if (p(i) < p(i + 1) && p(i + 1) < p(i + 2)) v = v + 1
        else if (p(i) > p(i + 1) && p(i + 1) > p(i + 2)) v = v + 1
      }

    v
  }

  println(solve(n, p))
}
  

