object Main{
  def main(args: Array[String]){
      val input=io.Source.stdin.getLines().mkString("\n")
      println(solve(input).toString.trim());
  }
  def solve(input:String):Int ={
    val g = input.split("\n")(1).split(" ").map(_ .toInt)
    var ret = 0
    for( i <- 1 until g.size-1){
    	if( ( g(i-1) < g(i) && g(i) <= g(i+1) )|| ( g(i-1) >= g(i) && g(i) > g(i+1) ) )
        {
         ret +=1
        }
    }
    ret
  }
}