import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val decimal = listOf(0,1,2,3,4,5,6,7,8,9)
    val N = sc.nextInt()
    val K = sc.nextInt()

    var D = listOf<Int>()
    for(i in 0..(K-1)){
        D += sc.nextInt()
    }
    D = D.distinct()
    var OK = decimal.filterNot{
            it in D
        }
    for(i in N..100000){
        if(i.toString().filterNot{
                    it.toString().toInt() in OK
                }.isEmpty()){
            println(i)
            return
        }
    }
}