function main() {
  const input = require("fs").readFileSync("/dev/stdin", "utf-8").trim();
  const lines = input.split('\n');
  const totalNum = lines[0].split(' ')[0].split('');
  const dislikeNum = lines[1].split(' ');
  const likeNum = [];
  for(let i = 0; i < 10; i++) {
    if(dislikeNum.indexOf(i + '') === -1) {
      likeNum.push(i + '');
    }
  }
  console.log(likeNum)
  console.log(getResult(totalNum, likeNum));
}

function getResult(sourceNum, likeNum) {
  const item = sourceNum[0];
  const resStr = sourceNum.length - 1 ? getResult(sourceNum.slice(1), likeNum) : '';
  if(likeNum.indexOf(item) > -1) {
    return resStr ?  [item, resStr].join('') : item;
  } else {
    const bigger = getBigger(likeNum, item);
    if(bigger) {
      let str = '';
      for(let i = 1; i < sourceNum.length; i++) {
        str += likeNum[0];
      }
      return bigger + str;
    } else {
      let str = '';
      for(let i = 0; i < sourceNum.length; i++) {
        str += likeNum[0];
      }
      return likeNum[0] === '0' ? likeNum[1] + str : likeNum[0] + str;
    }
  }
  return '';
}

function getBigger(arr, num) {
  for(let i = 0; i < arr.length; i++) {
    if(arr[i] > num) {
      return arr[i] + ''
    }
  }
  return null;
}

main();
