import java.util.Scanner
import kotlin.system.exitProcess

val arr = BooleanArray(10){true}
fun main(args: Array<String>) {
	val scanner = Scanner(System.`in`)
	val n = scanner.nextInt()
	val k = scanner.nextInt()
	repeat(k){ arr[scanner.nextInt()]=false }
	rec(n)
}

fun rec(n: Int) {
	val cs = n.toString().toCharArray()
	val strBld = StringBuilder()
	cs.forEachIndexed { i, c ->
		val d = c.toString().toInt()
		if (!arr[d]) {
			for (a in d + 1..9) {
				if (arr[a]) {
					strBld.append(a)
					repeat(cs.size - i - 1) { strBld.append(arr.indexOf(true)) }
					ans(strBld)
				}
			}
			var add=1
			repeat(cs.size-i){
				strBld.append(arr.indexOf(true))
				add*=10
			}
			rec(strBld.toString().toInt()+add)
		} else strBld.append(d)
	}
	ans(strBld)
}


fun ans(ans: StringBuilder){
	println(ans)
	exitProcess(0)
}