import java.util.Scanner

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

  val n  = sc.nextInt
  val av = Vector.fill(n)(sc.nextInt)

  def loop( vec: Vector[Int], target: Int = 1 ): Int = {
    val (_, fa) = vec.span(_ != target)
    (target, fa.isEmpty) match {
      case (1, true) => -1
      case (_, true) => n - (target - 1)
      case _ => loop(fa.tail, target + 1 )
    }
  }

  val res = loop(av)
  println(res)

}