object Main extends App {
  var get = readInt
  var list = readLine.split(" ")
  var sum = 0
  var i = 0
  while(i < get-2){
    var count = List(list(i),list(i+1),list(i+2)).sorted
    if(list(i+1)==count(1)){
        sum = sum + 1
    }
    i= i + 1
  }
  println(sum)
}