  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 _loop(n: Int, l: Int, a: String): String = {
            if (l <= 0) {
                a
            } else {
                val nn = n % 10
                if (ds.contains(nn)) {
                    _loop(n + 1, if (n == 9) l + 1 else l, a)
                } else {
                    _loop(n / 10, l - 1, nn.toString + a)
                }
            }
        }
        _loop(n, n.toString.length, "")
    }
  }
