import std.stdio, std.string, std.array, std.conv, std.algorithm, std.typecons, std.range, std.container, std.math, std.algorithm.searching, std.functional;

void main(){
    auto nk=readln().split.array;
    auto n=nk[0].to!int;
    string[] ds=readln().split.array;


    bool isSafe(int cur){
        string str=cur.to!string;
        return ds.all!(d=>!str.canFind(d));
    }

    foreach(current;n..100000){
        if(isSafe(current)){
            writeln(current);
            return;
        }
    }
}