object Main {
  def test(n: Int, ar: Array[Int]): Boolean = {
    var t = Array(n % 10)
    var r = n
    while (r > 0) {
      var tmp = r % 10
      t = t :+ tmp
      r = r / 10
    }
    val ch = t.sorted.distinct
    ch sameElements ar
  }

  def main(args: Array[String]): Unit = {
    val n = io.StdIn.readLine.split(" ").map(_.toInt)
    val dn = io.StdIn.readLine.split(" ").map(_.toInt)
    val ok = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) diff dn
    var t = n(0)
    var flag = true
    while(flag) {
      if(test(t, ok)) {
        println(t)
        flag = false
      } else {
        t += 1
      }
    }
  }
}