import java.util.Scanner

import scala.annotation.tailrec

object Main extends App {
  val sc = new Scanner(System.in)
  val n = sc.nextInt()
  val k = sc.nextInt()
  val ds = Vector.fill(k)(sc.nextInt())

  @tailrec
  def calc(int: Int): Int = {
    if (ds.forall(d => !s"$n".contains(s"$d"))) int
    else calc(int + 1)
  }

  println(s"${calc(n)}")
}
