object Main extends App {
    val List(amount: Int, countOfdislikeWord: Int) = readLine.split(" ").toList.map(_.toInt)
    val listOfDislikeWord = readLine.split(" ").toList.map(_.toInt)
    val answer = (amount to (10*amount)).find(p => p >= amount && !isContainsLikeNumber(listOfDislikeWord, p))
    println(answer.get)

    def isContainsLikeNumber(listOfDislikeWord: List[Int], amount: Int): Boolean = {
      // 合計金額を桁ごとにListにしたもの
      val amountList = amount.toString.toList.map(_.asDigit)
      amountList.exists(p => listOfDislikeWord.contains(p))
    }
}
