fun intList() = readLine()?.split(" ")?.map(String::toInt) ?: TODO()
fun main() {
    val (n, k) = intList()
    val d = intList()
    val numbers = listOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) - d
    val patterns = mutableListOf<Int>()
    fun gen(digits: Int, numbers: List<Int>, s: String) {
        if(s.isNotEmpty()) {
            patterns.add(s.toInt())
        }
        if (digits > 0) {
            numbers.forEach {
                gen(digits - 1, numbers, s + it)
            }
        }
    }
    gen(n.toString().length + 1, numbers, "")
    val min = patterns.filter { it >= n }.min()
    println(min.toString())
}
