object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val p = Array.fill[Int](n)(sc.nextInt)

    var count = 0
    p.sliding(3).foreach(a => {
      if (a.min != a(1) && a.max != a(1)) {
        count += 1
      }
    })

    println(count)
  }
}