import std.functional,
       std.algorithm,
       std.bigint,
       std.string,
       std.traits,
       std.array,
       std.range,
       std.stdio,
       std.conv;

void main() {
  int[] inputs = readln.chomp.split.to!(int[]);
  int N = inputs[0],
      K = inputs[1];
  string D = readln.chomp.split.join;

  while (any!(c => D.canFind(c))(N.to!string)) {
    N++;
  }

  N.writeln;
}
