import std.stdio, std.string, std.conv, std.array, std.algorithm, std.range;
 
void main()
{
    auto n = readln.chomp.split(" ")[0].to!int;
    auto ds = readln.chomp.split(" ").map!(to!string).join("");
 
    while (!setIntersection(ds, n.to!string).empty)
        ++n;
 
    writeln(n);
}