local n,k=io.read("n","n")
local d={}
for i=1,k do
    d[io.read("n")]=true
end
for i=n,10*n do
    local copi=i
    local checker=true
    while copi>0 do
        if d[copi%10] then
            checker=false
            break
        end
        copi=copi//10
    end
    if checker then
        print(i)
        return
    end
end