(function (in, n, s, t) {
  console.log(.slice(1).sort().join(''));
  in = in.split('\n');

  n = Number(in[0].split(' ')[0]);
  s = String(n);
  t = in[1].split(' ');

  while (true) {
    for (var i = 0; i < t.length; i++) {
      if (s.indexOf(t[i]) >= 0) {
        s = String(++n);
        break;
      }
    }
    if (i == t.length) {
      break;
    }
  }
  console.log(n);

}(require("fs").readFileSync("/dev/stdin", "utf8")));
