let N = readLine()!.characters.split(" ").map{Int(String($0))!}[0]
let D = readLine()!.characters.split(" ").map{String($0)}
for i in N..<100000 {
    var flag = false
    for c in D {
        if String(i).characters.contains(Character(c)) {
            flag = false
            break
        } else {
            flag = true
        }
    }
    if flag {
        print(i)
        break
    }
}