import java.util.*
import kotlin.system.exitProcess

val sc = Scanner(System.`in`)
val N = sc.nextInt()
val K = sc.nextInt()
val D = Array(K) { sc.nextInt() }

fun main(args: Array<String>) {
    for (i in 0..Int.MAX_VALUE) {
        dfs("", i)
    }
}

fun dfs(s: String, m: Int) {
    if (s != "" && s.toInt() >= N) {
        println(s)
        exitProcess(0)
    }
    if (s.length == m) {
        return
    }
    for (i in 0..9) {
        if (i !in D) {
            dfs(i.toString() + s, m)
        }
    }
}
