#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
const int maxn = 15;
const int inf = 0x3f3f3f3f;
int a[maxn];
int n, k;
bool check(int n) 
{
	for (int i = 1; i <= k; ++i)
		if (n == a[i])
			return false;
	return true;
}
int main() 
{
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= k; ++i)
		scanf("%d", &a[i]);
	for (int i = n;; ++i) 
	{
		int j = i;
		int aa;
		while (j > 0) {
			aa = j % 10;
			if (!check(aa))
			{
				break;
			}
			j /= 10;
		}
		if (j == 0) 
		{
			printf("%d\n", i);
			break;
		}
	}

	return 0;
}