fun main(args: Array<String>) {
    val x = readLine()!!.toInt()
    val y = readLine()!!.split(" ").map { it.toInt() }

    val ans = y.fold(Pair(0, (Triple(0,0,0)))) {n,t ->
     val current = Triple(n.second.second, n.second.third, t)
     when {
         listOf(current.first,current.second, current.third).sorted()[1] == current.second && (current.first != 0)-> {
             Pair(n.first + 1 , current)
         }
         else -> {
             Pair(n.first, current)
         }
     }
    }.first

    println(ans)
}
