import scala.collection.mutable.ArrayBuffer

object Main extends App {
	val sc = new java.util.Scanner(System.in)
	val pw = new java.io.PrintWriter(System.out)
	
	val n = sc.nextInt
	val a = Array.fill(n+1)(true)
	
	def f(p: Seq[Int], min: Int): Int = p match {
		case Seq() => 0
		case init :+ pi =>
			a(pi - 1) = false
			if (pi > min) f(init, min) else f(init, g(min)) + 1
	}
	
	def g(m: Int): Int = if (a(m)) m+1 else g(m+1)
	
	pw.println( f(Seq.fill(n)(sc.nextInt), 1) )
	pw.flush()
}