#include<iostream>
#include<cstdio>
using namespace std;
int sz[10];
bool check(int x)
{
	while (x != 0)
	{
		if (sz[x % 10])
			return false;
		else x /= 10;
	}
	return true;
}
int main()
{
	int N, K;
	cin >> N >> K;
	int a;
	for (int i = 1; i <= K; i++)
	{
		cin >> a;
		sz[a] = 1;
	}
	while (1)
	{
		if (check(N)) { cout << N; break; }
		else N++;
	}
}