#include <bits/stdc++.h>
using namespace std;

bool ok(int n, bool f[11]) {
	while(n > 0) {
		int x = n%10;
		if(f[x]) return false;
		n /= 10;
	}
	return true;
}
int main() {
	bool banned[11]{false};
	int num;
	int k;
	cin >> num >> k;
	for(int i = 1; i <= k; ++i) {
		int x;
		cin >> x;
		banned[x] = true;
	}
	while(!ok(num, banned)) ++num;
	cout << num;
	
}