fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val listOfNumbers = readLine()!!.split(" ").map(String::toInt)
    var deletionCount = 0
    var currentIndex = 1
    var found = false
    for (x in listOfNumbers) {
        if (x == currentIndex) {currentIndex++; found = true}
        else deletionCount++
    }
    if (found) println(deletionCount)
    else println(-1)
}