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.next())
  val xs = Vector(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) diff ds

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

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