var lines=[];
var reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});

reader.on('line', (line) => {
    lines.push(line)
})

reader.on('close', () => {
    var num = lines[0].split(" ")[0]
    var invalid = lines[1].split(" ")

    while (1) {
        if (!invalid.find(v => (num+"").includes(v)))
            break
        num++
    }
    console.log(num)
})
