import math._ object Main { def main(args: Array[String]) { val sc = new java.util.Scanner(System.in) val n = sc.nextInt val xs = (1 to n) map { e => sc.nextInt } var ans = 0 for (i <- 1 to xs.length-2) { if ((xs(i-1) < xs(i) && xs(i) > xs(i+1)) || (xs(i-1) > xs(i) && xs(i) < xs(i+1))) { if (xs(i-1) != xs(i+1)) { ans += 1 } } } println(ans) } }