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('').map(Number);

    for (var i = 0; i < result.length; i++) {
        while (badNum.indexOf(result[i]) !== -1) {
            result[i]++;
        }
    }

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

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