#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int M=1e6+7;
int read(){
	int ans=0,f=1,c=getchar();
	while(c<'0'||c>'9'){if(c=='-') f=-1; c=getchar();}
	while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar();}
	return ans*f;
}
int n,k,vis[10],xs[M],xp;
void find(int x,int len){
	xs[++xp]=x;
	if(len==5) return ;
	for(int i=0;i<=9;i++)if(!vis[i]) find(x*10+i,len+1);
}
int main(){
	n=read(); k=read();
	for(int i=1;i<=k;i++) vis[read()]=1;
	for(int i=0;i<=9;i++)if(!vis[i]) find(i,1);
	sort(xs+1,xs+1+xp);
	printf("%d\n",*lower_bound(xs+1,xs+1+xp,n));
	return 0;
}