object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val k = sc.nextInt()
  val ds = Array.fill(k)(sc.next().head).toSet
  var ans = 0
  var i = n
  while (ans == 0) {
    if ((i.toString.toList.toSet & ds).size == 0) {
      ans = i
    }
    i += 1
  }
  println(ans)
}
