#include <stdio.h>
bool ban[10];
bool can(int n)
{
	while (n)
	{
		if (ban[n%10])
			return false;
		n/=10;
	}
	return true;
}
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	for (int i=1;i<=k;++i)
	{
		int tmp;
		scanf("%d",&tmp);
		ban[tmp]=true;
	}
	while (!can(n))
		++n;
	printf("%d",n);
	return 0;
}
