void main()
{
    string[] tmp = readln.split;
    long n = tmp[0].to!long, k = tmp[1].to!long;
    long[] d = readln.split.to!(long[]);

    bool[] ok = new bool[10];
    ok[] = true;
    foreach (x; d)
    {
        ok[x] = false;
    }

    long len = tmp[0].length;
    long[] money = new long[len+1];
    foreach_reverse (i; 1 .. len+1)
    {
        money[i] += n % 10;
        money[i-1] += money[i] / 10;
        money[i] %= 10;
        n /= 10;

        while (!ok[money[i]])
        {
            if (money[i] == 9)
            {
                ++money[i-1];
                money[i] = 0;
            }
            else
            {
                ++money[i];
            }
        }
    }

    if (money[0] == 0)
    {
        money = money[1..$];
    }
    else
    {
        while (!ok[money[0]])
        {
            ++money[0];
        }
    }

    foreach (i, x; money)
    {
        x.write;
    }
    writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;