#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>

using namespace std;

typedef long long ll;
const int Maxn = 1e9 + 10;
const int N = 1e5 + 10;
const int INF=(0x7fffffff)/2;
int a[15];
int solve(int n){
	int b, c = 1;
	while(n){
		b = n % 10;
		if(a[b]){
			c = 0;
			break;
		}
		n /= 10;
	}
	if(c == 1)
		return 1;
	else
		return 0;
}


int main(){
	int n, k;
	while(~scanf("%d %d", &n, &k)){
		memset(a, 0, sizeof(a));
		for(int i = 0; i < k; i++){
			int t;
			cin >> t;
			a[t] = 1;
		}
		for(int i = n; ; i++){
		/*	int b, c = 1;
			while(i){
				b = n % 10;
				if(a[b]){
					c = 0;
					break;
				}
				n /= 10;
			}*/
			if(solve(i)){
				printf("%d\n", i);
				break;
			}
		}
	}
}