import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto rd = readln.split, n = rd[0].to!int, k = rd[1].to!size_t;
  auto d = readln.split.to!(int[]);
  auto db = new bool[](10);
  foreach (di; d) db[di] = true;

  for (auto e = 0; n >= 10 ^^ e; ++e) {
    for (;;) {
      auto m = n / 10 ^^ e % 10;
      if (!db[m]) break;
      n += 10 ^^ e;
    }
  }

  writeln(n);
}
