
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(readLine())
    var n = scanner.nextInt()
    val digits = readLine()!!.split(" ")

    while (true) {
        val nstr = n.toString()
        if (digits.any { it in nstr }) {
            n++
            continue
        } else {
            print(nstr)
            break
        }
    }
}