object Main extends App {
  val l1 = io.StdIn.readLine()
  val N = l1.split(" ")(0).toInt
  val K = l1.split(" ")(1).toInt

  val l2 = io.StdIn.readLine()
  val hateNumbers = l2.split(" ")

  (N to 10000).find((i) => {
    val inumbers = i.toString.split("").distinct
    hateNumbers.forall((h) => {
      ! inumbers.exists(_ == h)
    })
  }) match {
    case Some(n) => println(n)
    case None => println(10000)
  }
}