function Main(s) {
	s[0] = s[0].split(" ").map(a => parseInt(a));
	s[1] = s[1].split(" ").map(a => parseInt(a));
	var n = s[0][0];
	var k = s[0][1];
	var sl = s[1].length;
	while(f(n)) n++;
	
	console.log(n);
	
	function f(k){
		while(k){
			var m = k % 10;
			for(var i = 0; i < sl; i++){
				if(m === s[1][i]) return true;
			}
			k = Math.floor(k * 0.1);
		}
	}
}

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