#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<ctime>
#include<vector>
#include<queue>
#include<map>
#include<deque>
#include<stack>
#include<algorithm>
#define N 20
using namespace std;
const int INF=0x7fffffff;
const double Pi=acos(-1);
int K,D[N];
bool Check(int X)
{
	int i;
	while(X)
	{
		int T=X%10;
		for(i=1;i<=K;i++)if(T==D[i])return 0;
		X/=10;
	}
	return 1;
}
int main()
{
	int i,n;
	scanf("%d%d",&n,&K);
	for(i=1;i<=K;i++)scanf("%d",&D[i]);
	for(i=n;;i++)
	{
		if(Check(i))
		{
			printf("%d\n",i);
			return 0;
		}
	}
	return 0;
}