import java.util.*

fun main(args: Array<String>) {
    Scanner(System.`in`).use { sc ->
        var n = sc.nextInt()
        val k = sc.nextInt()
        val hate: Set<Char> = sc.asSequence().take(k).map {it[0]}.toSet()
        while (true) {
            if (n.toString().asSequence().none { c: Char ->
                hate.contains(c)
            }) {
                break
            }
            n++
        }
        println(n)
    }
}
