import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)

  val n = sc.nextInt
  val ps = Seq.fill(n)(sc.nextInt)

  val psx = 0 +: ps :+ 0
  val psx2 = psx.tail
  val psx3 = psx2.tail

  val res =
    psx3.foldLeft((0L, psx.head, psx2.head)){ case ((cnt, first, second), e) =>
      val b1 = first != 0 && e != 0
      val b2 = Seq(first, second, e).sorted.tail.head == second
      ( cnt + (if(b1 && b2) 1 else 0) ,second, e )
  }._1

  println(res)
}
