import 'dart:io';

void main(){
	int n, k;
	List<int> arr = stdin.readLineSync().split(" ").map((ele) => int.parse(ele)).toList();
	List<bool> bol = new List(10);
	n = arr[0];
	k = arr[1];
	arr = stdin.readLineSync().split(" ").map((ele) => int.parse(ele)).toList();
	arr.forEach((ele) => bol[ele] = true);
	for(int i = n; true; i++){
		int temp = i;
		bool test = false;
		while(temp > 0){
			test |= bol[temp%10]??false;
			temp = temp ~/ 10;
		}
		if(!test){
			print(i);
			return;
		}
	}
}