"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    let N = parseInt(arg[0].split(" ")[0]);
    const K = parseInt(arg[0].split(" ")[1]);
    
    const kRegexp = new RegExp("["+arg[1].replace(" ","")+"]");
    
    while(kRegexp.test(String(N))) {
        N++;
    }
    
    let answer = N;
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));