object Main extends App {
  val n = readInt
  val ps = readLine.split(" ").map(_.toInt)
  println((1 to n-2).map(i => if((ps(i-1)<ps(i) && ps(i)<ps(i+1)) || (ps(i-1)>ps(i) && ps(i)>ps(i+1)))1 else 0).sum)
}