'use strict';
function Main(input) {
  let price = input.split('\n')[0].split(' ')[0];
  let priceArray = price.split('');
  let hate = input.split('\n')[0].split(' ')[1];
  let hateList = input.split('\n')[1].split(' ');
  let out = '';
  let tmp;
  let terminate = false;
  for (let i=0; i < priceArray.length; i++) {
    for (let j=0; j<10; j++) {
      if (i == 0 && j == 0) continue;
      if (hateList.indexOf(j.toString()) == -1 && j >= priceArray[i]) {
        out += j.toString();
        break;
      } else if (hateList.indexOf(j.toString()) == -1) {
        tmp = j;
      } else if (hateList.indexOf(j.toString()) != -1 && j >= 9) {
        out += (tmp*10).toString();
        for(let k=0; k<priceArray.length-1; k++ ) {
          out += "0";
        }
        terminate = true;
        break;
      }
    }
    if (terminate == true) break;
  }
  console.log(`${out}`);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));