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(n.to!string, ds).empty)
        ++n;

    writeln(n);
}