import scala.collection.mutable.ArrayBuffer
import scala.util.control.Breaks
import java.lang.Math
object Main{
  def main(args:Array[String]) = {

    val sc = new java.util.Scanner(System.in)
    var N = sc.nextInt
    val K = sc.nextInt

    val hate = List.fill(K)(sc.nextInt)
    val all = List(0,1,2,3,4,5,6,7,8,9)

    val buf = new ArrayBuffer[Int]
    all.foreach(l =>{
      if(!hate.contains(l))buf+=l
    })
    val like = buf.toList

    var loop: Boolean = true
    var candidate: Int = N
    while(loop) {
      val candList = candidate.toString.toCharArray
      val check = candList.map(c => like.contains(c.toInt-48)).foldLeft(true)(_ && _)
      if(check){
        loop=false
      }else{
        candidate+=1
      }
    }

    println(candidate)


  }
}