#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 4000+5;
const int dx[] = {0,0,-1,1,-1,-1,1,1};
const int dy[] = {-1,1,0,0,-1,1,-1,1};
using namespace std;
bool vis[10];
bool judge(int x){
    while(x){
        int temp=x%10;
        if(vis[temp])
            return false;
        x/=10;
    }
    return true;
}
int main(){
    int n,k;
    scanf("%d%d",&n,&k);

    memset(vis,false,sizeof(vis));
    for(int i=1; i<=k; i++){
        int x;
        scanf("%d",&x);
        vis[x]=true;
    }

    for(int i=n; i<=10000; i++){
        if(judge(i)){
            printf("%d\n",i);
            break;
        }
    }
    return 0;
}