function main (input) {
  const inputRows = input.split('\n');
  let price = Number(inputRows[0].split(' ')[0]);
  const hateNumberLen = Number(inputRows[0].split(' ')[1]);
  const hateNumbers = inputRows[1].replace(' ', '');
  const regex = new RegExp(`[${hateNumbers}]`);

  while (regex.test(String(price))){
    price++;
  }

  // console.log(price);
  return price;
}

const input = `1000 8
1 3 4 5 6 7 8 9`;
// console.log(main(input));

console.log(main(require("fs").readFileSync("/dev/stdin","utf8")));

