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

void main()
{
  int n, k;

  readf("%d %d\n", &n, &k); 
  string ds = readln.chomp.replace(" ", "");

  while (any!(a => ds.canFind(a))(n.to!string)) {
    n++;
  }

  writeln(n);

}
