//自己写的，目测AC（因网络问题无法当场提交） 
#include <bits/stdc++.h> 
using namespace std;

int n,k;//n < 10000      k < 10
int a[15];

int check(int n){
	bool flag = false;
	for(int i = 0;i < k;i++){
		if(n == a[i]){
			if(flag == true)
				n++;
			if(n == 9)
				flag = true; 
			n++;
			check(n);
		}
		else
			return n;
	}
}

void work(int a){
	bool superflag = false;
	vector<int> v; 
	int g = 0;
	while(a != 0){
		g = a % 10;
		a /= 10;
		g = check(g);
		v.push_back(g);
	}
	for(int i = v.size() - 1;i >= 0;i--){
		if(v[v.size() - 1] == 10){
			cout << 1;
			superflag = true;
			continue;
		}
		cout << v[i];
	}
	if(superflag)
		cout << 0;
	cout << endl;
}

int main(){
	cin >> n >> k;
	for(int i = 0;i < k;i++)
		cin >> a[i];
	work(n);
	return 0;
}