object Main extends App {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt // 最初の数字を読み取る
    val seq = Seq.fill(n)(sc.nextInt) // nextIntがn回呼ばれる
    var c = 0

    for (i <- 1 to n - 2 ) yield {
        val (p1, p2, p3) = (seq(i - 1), seq(i), seq(i + 1))
        if (p1 < p2 && p2 < p3 || p1 > p2 && p2 > p3) c += 1
        c
    }

    println(c)
}