/**
 * Created by karayuu on 2018/07/03
 */
fun main(args: Array<String>) {
    var (n, k) = readLine()!!.split(" ").map { it.toInt() }
    val dislikeNums = readLine()!!.split(" ")
    var n_s = n.toString().map { it.toString() }

    while (!n_s.none { dislikeNums.contains(it) }) {
        n++
        n_s = n.toString().map { it.toString() }
    }

    print(n)

}
