fun main(args: Array<String>) {
    abc148d()
}

private const val MAX = Long.MAX_VALUE / 3

fun abc148d() {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map { it.toLong() }.toLongArray()

    var answer = MAX

    val indexOfFirst1 = aList.indexOfFirst { it == 1L }

    if (indexOfFirst1 == -1) return println(-1)

    var curr = 0L
    var value = 2L
    for (j in indexOfFirst1..aList.lastIndex) {
        if (aList[j] == value) {
            curr++
            value++
        }
    }

    answer = Math.min(answer, n - curr - 1)

    if (answer == MAX) answer = -1

    println(answer)
}
