import io.{StdIn => in}

object Main extends App {
  val Array(sn, sk) = in.readLine.split(" ")
  val n = sn.toInt
  val k = sk.toInt
  val d = in.readLine.split(" ").map(_.toInt)
  val digits = Array.range(0, 11) diff d
  // println(digits.mkString(" "))

  val res = sn.reverse./:(0,0,1)((acc,c) => {
    val i = c.toString.toInt + acc._2
    val dn = if(d.exists(_ == i)) digits.minBy(e => if(e > i) e else 11) else i
    // print(i + "," + dn + " ")
    if(dn == 10) (acc._1, 1, acc._3*10)
    else (acc._1+dn*acc._3, 0, acc._3*10)
  })

  val ans = if(res._2 == 1) {
    val dn = if(d.exists(_ == 1)) digits.minBy(e => if(e > 1) e else 11) else 1
    res._1 + dn * res._3
  } else res._1

  println(ans)
}