#include<set>  
#include<map>  
#include<stack>  
#include<cmath>  
#include<cstdio>  
#include<queue>  
#include<vector>  
#include<cstring> 
#include<climits>  
#include<iostream> 
#include<algorithm> 
using namespace std; 
int read(){ 
    int f=1,x=0; 
    char c=getchar(); 
    while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();} 
    while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();} 
    return f*x; 
}
#define MAXN 300
#define INF 0x3f3f3f3f
int pan[10];
bool check(int x){
	while(x){
		if(pan[x%10]) return 0;
		x/=10;
	}
	return 1;
}
int main(){
	int n=read(),k=read();
	for(int i=1;i<=k;i++)
		pan[read()]=1;
	while(1){
		if(check(n)){
			printf("%d\n",n);
			return 0;
		}
		n++;
	}
    return 0;
}