#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
	ios :: sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	while (cin >> n >> k) {
		bool like[10];
		for (int i = 0; i < 10; ++i) 
			like[i] = 1;
		for (int i = 0; i < k; ++i) {
			int tmp = 0;
			cin >> tmp;
			like[tmp] = 0;
		}
		for (int i = n; i < 100000; ++i) {
			int tmp = i;
			bool fd = 1;
			while (tmp) {
				if (!like[tmp%10]) {
					fd = 0;
					break;
				}
				tmp/=10;
			}
			if (fd) {
				cout << i << endl;
				break;
			}
		}
	}
	return 0;
}