function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0].split(" ")[0], 10);
  var nums = input[1].split(" ").map((n) => parseInt(n, 10));

  while (true) {
    var num = N.toString().split("");

    if (num.every((n) => nums.indexOf(parseInt(n, 10)) == -1)) {
      break;
    } else {
      N++;
    }
  }

  console.log(N);
}

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