//#include<bits/stdc++.h>
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<algorithm>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<ctime>
#include<map>
#include<stack>
#include<string>
using namespace std;
#define ll long long
const int inf = 0x3f3f3f3f;
const int maxn =105;
int n,k;
int v[20];
bool f(int x)
{
	while(x)
	{
		int m=x%10;
		if(v[m]==1)return 0;
		x/=10;
	}
	return 1;
}
int main(void)
{
	cin>>n>>k;
	for(int i=1;i<=k;i++)
	{
		int a;
		cin>>a;
		v[a]=1;
	}
	while(1)
	{
		if(f(n))
		{
			cout<<n<<endl;
			return 0;
		}
		n++;
	}
	
}
