import std.stdio, std.string, std.conv, std.array, std.algorithm;
import std.uni, std.range, std.math, std.container, std.datetime;
import core.bitop;

immutable long MOD = 1_000_000_007;

void main(){
    char[] buf; readln(buf);
    auto input = buf.split.to!(int[]);
    auto N = input[0], K = input[1];
    readln(buf);
    auto D = buf.split;
    int ans = N;

    while(true){
        bool flag = true;
        auto anss = ans.to!string;
        
        foreach(d ; D){
            if(anss.canFind(d)){
                flag = false;
                break;
            }
        }

        if(flag){
            writeln(ans);
            return;
        }

        ++ans;
    }
}