
fun main(args: Array<String>) {
    val line = readLine()!!.split(' ')
    var amount = Integer.parseInt(line[0])

    val ignore = readLine()!!.split(' ')


    while(true) {
        var flag = false
        ignore.forEach {
            if(amount.toString().contains(it)) {
                flag = true
            }
        }
        if(!flag){
            break
        }
        amount++
    }
    println(amount)
}