#include <bits/stdc++.h>
#pragma warning (disable:4996)

using namespace std;
using ll = long long;
using LL = ll;
using ull = unsigned long long;
using uLL = ull;
#define clean_0(A) memset((A),0,sizeof(A))
#define clean_1(A) memset((A),-1,sizeof(A))
#define For(i,a,b) for(int (i)=(a);(i)<=b;++(i))
#define Max_(a,b) ((a)>=(b)?(a):(b))
#define Min_(a,b) ((a)<=(b)?(a):(b))
template<typename T>
inline T Max(T a, T b) { return a >= b ? a : b; }
template<typename T>
inline T Min(T a, T b) { return a <= b ? a : b; }

constexpr int INF = 0x7F7F7F7F;
constexpr double eps = 1e-9;

constexpr ll mod1 = 197;
constexpr ll mod2 = 19260817;
constexpr ll mod3 = ll(1e8) + 7;
constexpr ll mod4 = ll(1e9) + 7;;
constexpr ll mod5 = 998244353;
constexpr int mod = mod4;

constexpr int maxn = int(3e5) + 1;
constexpr int MAXN = maxn;
namespace io {

#define in(a) (a=read())
#define out(a) write(a)
#define outn(a) (out(a),putchar('\n'))

#define I_int  int
	inline I_int read() {
		I_int x = 0, f = 1; char c = getchar();
		while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); }
		while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
		return x * f;
	}
	template<typename T>
	bool scan_d(T& ret)
	{
#define p(x) ((x)>='0'&&(x)<='9')
		int c; int sgn;
		if (c = getchar(), c == EOF)return false;
		while (c != '-' && !p(c))c = getchar();
		sgn = (c == '-') ? -1 : 1;
		ret = (c == '-') ? 0 : c - '0';
		while (c = getchar(), p(c))ret = ret * 10 + c - '0';
		ret *= sgn;
		return true;
#undef p
	}
	char F[200];
	template<typename T>
	inline void write(T x) {
		if (x == 0) { putchar('0'); return; }
		auto tmp = x > 0 ? x : -x;
		if (x < 0) putchar('-');
		int cnt = 0;
		while (tmp > 0) {
			F[cnt++] = tmp % 10 + '0';
			tmp /= 10;
		}
		while (cnt > 0) putchar(F[--cnt]);
	}
	void read(char* s, int Arr[], size_t n)
	{
		for (size_t i = 0; i < n; ++i)Arr[i] = strtoll(s, &s, 10);
	}
#undef I_int

}
using namespace io;



/*template<typename T>
constexpr T _gcd(T a, T b)
{
	return b ? _gcd(b, a % b) : a;
}
template<typename T>
constexpr T combinator(T n, T m, T Mod = mod - 1)
{
	m = min(m, n - m);
	T ret = 1;
	for (T i = 1; i <= m; ++i)
	{
		ret = ret * (n - m + i) / i % Mod;
	}
	return ret;
}
template<typename T>
constexpr T poww(T a, T b, T Mod = mod)
{
	T ret = 1;
	a %= Mod;
	b %= Mod - 1;
	if (b < 0)b += Mod - 1;
	while (b)
	{
		if (b & 1)ret = ret * a % Mod;
		a = a * a % Mod;
		b >>= 1;
	}
	return ret;
}

struct Combinator
{
	static constexpr int Mod = ::mod;
	static constexpr int Maxn = ::maxn;
	int dp[Maxn][Maxn];//this is C(n,m)%(mod-1)
	constexpr Combinator() :dp()
	{
		for (int i = 0; i < Maxn; ++i)
		{
			for (int j = 0; j <= i; ++j)
			{
				if (j == 0) dp[i][j] = 1;
				else if (i == j) dp[i][j] = 1;
				else dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % (Mod - 1);
			}
		}
	}
};*/


int main()
{
	int n = 0, k = 0;
	while (cin >> n >> k)
	{
		int a[10] = { 0 };
		int ans = 0;
		int flag = 0;
		int x;
		for (int i = 0; i < k; i++)
		{
			scanf("%d", &x);
			a[x]=1;
		}
		for (int i = n; i < 1000000; i++)
		{
			int t = i;
			flag = 0;
			while (t)
			{
				int p = t % 10;
				if (a[p] != 0)
				{
					flag = 1;
					break;
				}
				t /= 10;
			}
			if (flag == 1)
				continue;
			else
			{
				ans = i;
				break;
			}
			//printf("%d ",i);
		}
		printf("%d", ans);
	}
}

Measured memory_bytes: 256