object Main extends App {
  val n = io.StdIn.readLine()
  val p = io.StdIn.readLine().split(" ")
  val pSize = p.size
  val maxIndex = pSize - 1
  var startIndex = 0
  var result = 0
  while (startIndex + 2 <= maxIndex) {
    val i1 = p(startIndex)
    val i2 = p(startIndex + 1)
    val i3 = p(startIndex + 2)
    if (((i1 < i2) && (i2 < i3)) || ((i3 < i2) && (i2 < i1))) result += 1
    startIndex += 1
  }
  println(result)
}