import java.util.*

fun check(x: Int, D: List<String>): Boolean {
    val xs = x.toString()
    return !D.any { s -> xs.contains(s) }
}

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val N = sc.nextInt()
    val K = sc.nextInt()
    val D = (1..K).map { sc.next() }.toList()
    var ans = N
    while (true) {
        if (check(ans, D)) {
            println(ans)
            break
        }
        ans++
    }
}