object Main extends App {
  val sc = new java.util.Scanner(System.in)
  var n = sc.nextInt()
  val k = sc.nextInt()
  val d = Set.fill(k)(sc.nextInt())

  def ng(n: Int): Boolean = {
    List(1, 10, 100, 1000, 10000).exists(x =>
      x <= n && d.contains((n % (x * 10)) / x)
    )
  }

  while (ng(n)) {
    n += 1
  }
  println(n)
}
