fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(' ').map(String::toInt)
    val q = BooleanArray(10);
    readLine()!!.split(' ').map(String::toInt).forEach {
        q[it] = true
    }
    var ans = n
    while (!f(ans, q)) ans++
    println(ans)
}

fun f(a : Int, q : BooleanArray) : Boolean {
    a.toString().forEach {
        if (q[it - '0']) return false
    }
    return true
}