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

int[] integerDigits(int n) {
    if (n == 0) return [0];
    return text(abs(n)).map!(e => cast(int)(e - '0')).array;
}

int calc(int n, int[] d) {
    for (int i = n; ; i++) {
        if (integerDigits(i).sort().setIntersection(d).empty)
            return i;
    }
    assert(false);
}

void main() {
    int n, k; scan(n, k);
    auto d = readints;
    writeln(calc(n, d));
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;
