#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
int n, k;
bool a[10];
int main() {
	while(~scanf("%d %d", &n, &k)){
		for(int i = 0; i < 10; i++) a[i] = false;
		for (int j = 0; j < k; j++) {
			int x;
			scanf("%d", &x);
			a[x] = true;
		}
		while (1){
			int y = n;
			bool flag = true;
			while (y  > 0) {
				if (a[y % 10]) {
					flag = false;
					break;
				}
				y /= 10;
			}
			if (flag) break;
			n++;
		}
		printf("%d\n", n);
		}
}