import java.util.Scanner

object Main {
    def main(args: Array[String]): Unit = {
        val scanner = new Scanner(System.in)
        val n: Int = scanner.nextInt
        val k: Int = scanner.nextInt
        val hates: List[Int] = List.fill(k)(scanner.nextInt)

        println(calc(n, hates))
    }

    def calc( n: Int, hates: List[Int]): Int ={
      (n to (10*n)).find(p => p >= n && !isIncludingHateNum(p, hates)).get
    }

    def isIncludingHateNum(payment: Int, hates: List[Int]): Boolean ={
      val pays:List[Int] = (payment.toString.grouped(1)).toList.map(_.toInt)
      pays.exists(hates.contains(_))
    }
}
