import io.StdIn.readInt
import annotation.tailrec
import collection.mutable.ListBuffer
import collection.Searching._

object Main extends App {
  val n = readInt
  val as = Seq.fill(n)(readInt)
  val vs = ListBuffer.empty[Int]

  println(solve(0, 0, as, vs))

  @tailrec def solve(pos: Int, res: Int, as: Seq[Int], vs: ListBuffer[Int]): Int = {
    if (pos == 1) res
    else vs.search(pos) match {
      case Found(_) => -1
      case InsertionPoint(i) => {
        vs.insert(i, pos)
        solve(as(pos) - 1, res + 1, as, vs)
      }
    }
  }
}
