#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include <list>
using namespace std;
int flag[20],a[30];
int main()
{       
    int n,k;
    scanf("%d %d",&n,&k);
    memset(flag,0,sizeof(flag));
    memset(a,0,sizeof(a));
    for(int i=1;i<=k;++i){
    	int u;
    	scanf("%d",&u);
    	flag[u]=1;
	}
	int p=1;
	while(n>0){
		int t=n%10;
		if(flag[t]){
			for(int i=t+1;i<=9;++i){
				if(!flag[i]){
					a[p++]=i;
					break;
				}
			}
		}
		else{
			a[p++]=t;
		}
		n/=10;
	}
	for(int i=p-1;i>=1;--i){
		printf("%d",a[i]);
	}
	printf("\n");
		return 0;
}