#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef vector<int> vi;

#define all(cont) cont.begin(), cont.end()
#define fr(i, a, b) for(int i = a ; i < b ; i++)
#define frr(i, a, b) for(int i = a ; i >= b ; i--)
#define reset(i,n) memset(i, n, sizeof(i))
#define infile freopen("input.in","r",stdin);
#define boostIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define sz(x) ((int)(x).size())

// ull gcd(ull a, ull b) { return b? gcd(b,a%b): a; } //if b == 0 return a 
// ull lcm(ull a, ull b) { return a*b / gcd(a,b); }
void swap(int *a, int *b){ull t = *a; *a = *b; *b = t;}

string str;
int t, n, k, temp;
bool cek[10];

void read(){
	// infile
	reset(cek, true);
	cin >> str >> k;
	fr(i, 0, k){
		cin >> temp;
		cek[temp] = false;
	}
	// getline(cin, str);
}

void solve(){
	int id;
	fr(i, 0, str.size()){
		id = str[i]-48;	
		// cout << "id : " << id << '\n';
		// cout << "cek : " << cek[id] << '\n';
		while(cek[id] != true){
			// cout << "cek : " << cek[id] << '\n';
			// cout << "id : " << id << '\n';
			// cout << "run";
			id++;
		}
		// cout << "id : " << id << '\n';
		cout << id;
	}
}

int main(){
	boostIO
	n = 1;
	fr(i, 0, n){
		read();
		solve();
		// cout << "run";
	}

	cout << '\n'; 
	return 0;
}
