#include <iostream>
using namespace std;

const int MAXN = 10;
int n, k, d[MAXN];

bool check(int a) {
	while (a) {
		if (d[a % 10])
			return 1;
		a /= 10;
	}
	return 0;
}

int main() {
	cin >> n >> k;
	for (int i = 0; i < k; i++) {
		int a;
		cin >> a;
		d[a] = 1;
	}
	for (int i = n;  i < 1e8; i++) {
		if (check(i))
			continue;
		cout << i;
		break;
	}
}