#include <bits/stdc++.h>
#include<unordered_map>
#define ll long long
using namespace std;
#define sd(n) scanf("%d",&n)
#define clr(a) memset(a,0,sizeof(a))
int etr[11];
int main(){int K;string N;cin>>N;int lst;
	scanf("%d",&K);int k;scanf("%d",&lst);etr[lst]=1;
	for(int i=1;i<K;++i){scanf("%d",&k);
		etr[k]=1;
	}int cnt=1;
	for(int i=0;i<N.size();++i){
		if(etr[N[i]-'0']==1){if(cnt==1)
		N[i]+=1;
		else N[i]=lst+'0';
		}
	} 
	for(int i=0;i<N.size();++i){
printf("%d",N[i]-'0');
}
	
	
}