object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val p = Array.fill(n)(sc.nextInt())
  println {
    (1 until n - 1).count(i => {
      val sorted = p.slice(i - 1, i + 2).sorted
      p(i) == sorted(1)
    })
  }
}
