import std.stdio,std.array,std.conv,std.string,std.algorithm;

void main(){
    string[] inputStr = readln().split;

    int n = to!int(inputStr[0]);
    int k = to!int(inputStr[1]);
    string[] d = readln().split;

    int count = 0;
    while(true){
        count = 0;
        for(int j=0;j<to!string(n).length;j++){
            for(int a=0;a<d.length;a++){
                if((to!int(to!string(n)[j])-48) == to!int(d[a])) count++;
            }
        }
        if(count == 0) break;
        n++;
    }
    write(n);
}
