import java.util.Scanner
import java.util.ArrayList

fun main(args: Array<String>){
    val sc = Scanner(System.`in`)
    val N = sc.nextInt()
    var arraylist = ArrayList<Int>()
    var counter = 0
    for(i in 0 until N){
       arraylist.add(sc.nextInt())
    }
    for(i in 1 until N - 1){
       if(arraylist.elementAt(i-1) < arraylist.elementAt(i)){
          if(arraylist.elementAt(i) <= arraylist.elementAt(i+1)){
              counter++
          }
       }else if(arraylist.elementAt(i) > arraylist.elementAt(i+1)){
           counter++
       }
    }
    println(counter)
}