#include <bits/stdc++.h>
#define ll long long
#define PII pair < int, int >
#define x first
#define y second

using namespace std;
int n, k, a[10], u = 1;
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n >> k;
	for (int i = 1, x; i <= k; i++) cin >> x, a[x] = 1;
	while (1){
		int x = n;
		u = 1;
		while (x){
			if (a[x%10]) u = 0;
			x /= 10;
		}
		if (u) return cout << n, 0;
		n++;
	}
	
}
