object Main extends App {

  import scala.io.StdIn.readLine
  val Array(n, k) = readLine().trim.split(" ")
  val nl = n.length
  val ds = readLine().trim.split(" ").map(_.toInt)
  val ls = (0 to 9).filterNot(i => ds.contains(i))
  val ns = n.split("").map(_.toInt)
  val arr = Array.fill(nl)(0)
  for (i <- 0 until nl) {
    if (ls.contains(ns(nl-1-i))) {
      arr(nl-1-i) = ns(nl-1-i)
    } else {
      arr(nl-1-i) = ls.find(l => ns(nl-1-i) < l).get
    }
  }
  println(arr.mkString)

}
