import java.util.*

fun main(args:Array<String>){
    var (n,k) = readLine()!!.split(" ").map{it.toInt()}
    val d = readLine()!!.split(" ").map{it.toInt()}.toSet()
    while(true){
        var t = n
        var ok = true
        while(t > 0){
            if(d.contains(t % 10)) ok = false
            t /= 10
        }
        if(ok){
            println(n)
            break
        }
        n++
    }
}
