// inputに入力データ全体が入る
function Main(input) {
    var N = input[0].split(" ")[0]-0;
    var K = input[0].split(" ")[1]-0;
    var list = input[1].split(" ").join("");
    var ex = new RegExp("[" + list + "]");
    while(true){
        if(!ex.test(N.toString())) break;
        N++;
    }
    console.log(N);
}

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