using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
	public Program() { }

	static void Main(string[] args)
	{
		new Program().prog();
	}
	Scanner cin;
	const int MOD = 1000000007;
	const int INF = int.MaxValue;
	const double EPS = 1e-7;
	const double PI = 3.1415926536;

	void prog()
	{
		cin = new Scanner();
		int[,] dir8 = new int[8, 2] { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 }, { 1, 1 } };
		int[,] dir4 = new int[4, 2] { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };

		int N = cin.nextInt();
		int K = cin.nextInt();
		int[] d = new int[10];
		int min = 0, max = 0;
		for (int i = 0; i < K; i++)
		{
			int buf = cin.nextInt();
			d[buf] = 1;
		}
		for (int i = N; i < N*100; i++)
		{
			if (check(i, d))
			{
				Console.WriteLine(i);
				return;
			}
		}
		/*
		for (int i = 1; i < 10; i++)
		{
			if (d[i] == 0)
			{
				min = i;
				break;
			}
		}
		for (int i = 9; i > 0; i--)
		{
			if (d[i] == 0)
			{
				max = i;
				break;
			}
		}
		string num = N.ToString();
		string ans = "";
		bool flag = false;
		bool flag2 = false;
		for (int i = 0; i < num.Length; i++)
		{
			if (flag)
			{
				ans += max.ToString();
			}
			else
			{
				if (d[int.Parse(num[i].ToString())] == 0)
				{
					ans += num[i];
				}
				else
				{
					flag = true;
					for (int j = int.Parse(num[i].ToString()) - 1; j > 0; j--)
					{
						if (d[j] == 0)
						{
							ans += j.ToString();
							flag2 = true;
						}
					}
					if (!flag2)
					{
						ans += "0";
					}
				}
			}
		}
		Console.WriteLine("min: {0}",min);
		Console.WriteLine("max: {0}",max);
		Console.WriteLine(ans);
		flag = false;
		int minzero = min;
		if (d[0] == 0) minzero = 0;
		for (int i = num.Length - 1; i >= 0; i--)
		{
			if (int.Parse(ans[i].ToString()) == max)
			{
				ans = strChange(ans, i, minzero.ToString()[0]);
			}
			else
			{
				for (int j = int.Parse(ans[i].ToString()); j < 10; j++)
				{
					if (d[j] == 0)
					{
						ans = strChange(ans, i, j.ToString()[0]);
						flag = true;
						break;
					}
				}
				if (flag)
				{
					break;
				}
			}
		}
		Console.WriteLine(ans);
		/*
		if (int.Parse(num[0].ToString()) > max)
		{
			Console.Write(min);
			for (int i = 0; i < num.Length; i++)
			{
				if (d[0] == 1)
				{
					Console.Write(0);
				}
				else
				{
					Console.WriteLine(min);
				}
			}
		}
		else
		{
			int next = 0;
			for (int i = int.Parse(num[0].ToString()); i < 10; i++)
			{
				if (d[i] == 0)
				{
					next = i;
					break;
				}
			}
		}*/
	}
	// 文字列の一文字書き換え
	string strChange(string str, int n, char c)
	{
		return (str.Substring(0, n) + c + str.Substring(n + 1));
	}
	bool check(int ans, int[] d)
	{
		string s = ans.ToString();
		for (int i = 0; i < s.Length; i++)
		{
			if (d[int.Parse(s[i].ToString())] == 1)
			{
				return false;
			}
		}
		return true;
	}
}

class Scanner
{
	string[] s;
	int i;

	char[] cs = new char[] { ' ' };

	public Scanner()
	{
		s = new string[0];
		i = 0;
	}

	public string next()
	{
		if (i < s.Length) return s[i++];
		string st = Console.ReadLine();
		while (st == "") st = Console.ReadLine();
		s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
		i = 0;
		return next();
	}

	public int nextInt()
	{
		return int.Parse(next());
	}

	public long nextLong()
	{
		return long.Parse(next());
	}

	public double nextDouble()
	{
		return double.Parse(next());
	}
}

Measured memory_bytes: 6744