

object Main extends App {

  val n = scala.io.StdIn.readInt()
  val pArr = scala.io.StdIn.readLine().split(" ").map(_.toInt)


  def solve() = {
    var cnt = 0
    for(i <- 1 until n-1) {
      val list = Seq(pArr(i-1), pArr(i), pArr(i+1)).sorted
      if(list(1) == pArr(i)) cnt += 1
    }
    cnt
  }

  println(solve)

}
