function main(input) {
    var data = input[0].split(' ').map(Number);

    var n = data[0];

    var badNum = input[1].split(' ').map(Number);

    var result = n.toString().split('').reverse().map(Number);
    for (var i = 0; i < result.length; i++) {
        while (badNum.indexOf(result[i]) !== -1) {
            result[i]++;
            if (result[i] > 9) {
                if (i >= result.length - 1) {
                    result.push(0);
                }

                result[i + 1]++;
                result[i] = 0;
            }
        }
    }

    console.log(result.reverse().join(''));
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n'));
