fun main(args:Array<String>){
  var n = readLine()!!.toInt()
  var p = readLine()!!.split(" ").map{it.toInt()}
  var cnt = 0
  for(i in 1..n-2){
    if(p[i-1] < p[i] && p[i] < p[i+1])cnt++
  	else if(p[i-1] > p[i] && p[i] > p[i+1])cnt++
  }
  println(cnt)
}