object Main extends App {
  val input = readLine.split(' ').map(_.toInt)
  val n = input(0)
  val d = readLine.split(' ').map(_.toInt)
  val c = n to 10000
  val ans = c.find{ x => 
    val xs = x.toString.toList.map(_.asDigit)
    d.intersect(xs).isEmpty
  }
  println(ans.get)
}