import java.util.*

fun main(args: Array<out String>?): Unit {
    val n = readLine()!!.trim().toInt()
    val digits = read(n)
    val isAppear = BooleanArray(n * (n + 1) / 2 + 1){false}
    for (left in digits.indices) {
        if (digits[left] in isAppear.indices) isAppear[digits[left]] = true
        if (digits[left] != 0) {
            var right = left + 1
            var current = digits[left]
            while(right in digits.indices && current in isAppear.indices) {
                current *= 10
                current += digits[right++]
                if (current in isAppear.indices) isAppear[current] = true
            }
        }
    }
    println(isAppear.indices.find{!isAppear[it]})
}
fun read(k: Int): List<Int> {
    val stack = Stack<List<Int>>()
    var count = 0
    while(count < k){
        stack.add(readLine()!!.trim().split(' ').map(String::toInt))
        count += stack.peek().size
    }
    return stack.flatten()
}
