  // C - こだわり者いろはちゃん / Iroha's Obsession https://atcoder.jp/contests/abc042/tasks/arc058_a

  import scala.io.Source

  object Main extends App {
    val xs = Source.stdin.getLines()
    val Array(n, k) = xs.next().split(' ').map(_.toInt)
    val ds = xs.next.split(' ').map(_.toInt)

    println(solve(n, ds))

    def solve(n: Int, ds: Seq[Int]): String = {
      def check(n: Int): Boolean = {
        var f = true
        var nn = n
        while (nn > 0) {
          val nnn = nn % 10
          if (ds.contains(nnn))
            f = false
          nn = nn / 10
        }
        f
      }

      var a = ""
      for (i <- n to 100000) {
        if (check(i)) {
          return i.toString
        }
      }
      a
    }
  }
