object Main extends App {
  import scala.collection.mutable.{Set => mSet}
  val Array(n,k) = readLine.split(" ").map{_.toInt}
  val d:mSet[Int] = mSet()
  readLine.split(" ").map{_.toInt}.toList.foreach{d += _}
  var payment:mSet[Int] = mSet()
  for (x <- n.toString.map{_.asDigit}) payment += x
  var ans = n
  while(!(d & payment).isEmpty) {
    ans += 1
    payment = mSet()
    for (x <- ans.toString.map{_.asDigit}) payment += x
  }
  println(ans)
}