function myout(text){console.log(text);}//standard output
function Main(input) {
	//input = parseInt(input);
	//input = input.trim().split(" ");
	input = input.trim().split("\n");
	//input = input.trim().split(" ").map((a)=>Number(a));
	//input = input.trim().split("\n").map((a)=>Number(a));
  var N = parseInt(input[0].split(" "));
  var list = input[1].split(" ");
  
  while(true){
    var tmp = N.toString().split("");
    var breakFlag = true;
    for(var i = 0; i < tmp.length; i++){
      if(list.indexOf(tmp[i]) != -1){
         breakFlag = false;
      }
    }
    if(breakFlag){
       break;
    }else{
      N++;
    }
  }
  myout(N);
}

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