import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val ps = new Array[Int](n)
    for (i <- ps.indices) {
      ps(i) = sc.nextInt()
    }

    var ans = 0
    for (i <- 1 until n - 1) {
      val arr = Array(ps(i - 1), ps(i), ps(i + 1))
      if (ps(i) != arr.min && ps(i) != arr.max) ans += 1
    }

    println(ans)
  }
}