Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K.
She is shopping, and now paying at the cashier.
Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change).
However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.
Find the amount of money that she will hand to the cashier.

-----Constraints-----
 -  1 ≦ N < 10000
 -  1 ≦ K < 10
 -  0 ≦ D_1 < D_2 < … < D_K≦9
 - \{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}

-----Input-----
The input is given from Standard Input in the following format:
N K
D_1 D_2 … D_K

-----Output-----
Print the amount of money that Iroha will hand to the cashier.

-----Sample Input-----
1000 8
1 3 4 5 6 7 8 9

-----Sample Output-----
2000

She dislikes all digits except 0 and 2.
The smallest integer equal to or greater than N=1000 whose decimal notation contains only 0 and 2, is 2000.

Difficulty: EASY

Solutions:
import itertools

def cal(N, target_num, keta):
	answer = float('inf')
	for p in itertools.product(target_num, repeat=keta):
		temp = 0
		for (i, num) in enumerate(p):
			temp += num * 10 ** i
		if temp >= N:
			answer = min(answer, temp)
	return answer

def __starting_point():
	(N, K) = map(int, input().split())
	D = set(list(map(int, input().split())))
	base = set(range(10))
	target_num = base - D
	keta = len(str(N))
	answer = min(cal(N, target_num, keta), cal(N, target_num, keta + 1))
	print(answer)
__starting_point()


import sys
import numpy as np
read = sys.stdin.readline

def main(n, k, a):
	for i in np.arange(n, 100000):
		ok = True
		j = i
		while j:
			ok &= j % 10 not in a
			j //= 10
		if ok:
			print(i)
			break

def __starting_point():
	(n, k) = np.fromstring(read(), dtype=np.int32, sep=' ')
	a = np.fromstring(read(), dtype=np.int32, sep=' ')
	main(n, k, a)
__starting_point()


(N, K) = map(int, input().split())
unlike_list = set(map(str, input().split()))

def judge(num):
	for i in str(num):
		if i in unlike_list:
			return False
	return True
ans = False
while not ans:
	if judge(N):
		ans = True
	else:
		N += 1
print(N)


(n, k) = list(map(int, input().split()))
d = list(map(int, input().split()))
while n < 10 ** 5:
	x = str(n)
	if all((int(i) not in d for i in x)):
		print(n)
		return
	n += 1


(n, k) = list(map(int, input().split()))
d = list(input().split())
ans = n
find = False
while find == False:
	p = str(ans)
	find = True
	for i in range(len(p)):
		if p[i] in d:
			find = False
			break
	if find == False:
		ans += 1
print(ans)


import sys
(N, K) = list(map(int, input().split()))
D = list(map(int, input().split()))
while True:
	for x in [int(n) for n in str(N)]:
		if x in D:
			break
	else:
		print(N)
		return
	N += 1


(total, k) = list(map(int, input().split()))
d = list(map(int, input().split()))

def total_to_digits(total):
	return list(map(int, list(str(total))))

def find_lowest_denomination(total, d):
	res = None
	for i in range(total, 99999):
		digits = list(total_to_digits(i))
		if not set(digits) & set(d):
			print(i)
			return
find_lowest_denomination(total, d)


(n, k) = list(map(int, input().split()))
a = list(map(str, input().split()))
while True:
	for j in str(n):
		if j in a:
			break
	else:
		break
	n += 1
print(n)


def dfs(A: list):
	if len(A) > len(str(n)) + 1:
		return
	if len(A) and (x := int(''.join(A))) >= n and (ans[0] > x):
		ans[0] = x
		return
	for v in d:
		if v == '0' and len(A) == 0:
			next
		A.append(v)
		dfs(A)
		A.pop()
(n, k) = list(map(int, input().split()))
d = sorted(list(set([str(i) for i in range(10)]) - set(input().split())))
ans = [10 ** 10]
dfs([])
print(ans[0])


(n, k) = input().split()
l = list(map(int, input().split()))
checkNum = [i for i in range(11)]

def find(x):
	while x != checkNum[x]:
		checkNum[x] = checkNum[checkNum[x]]
		x = checkNum[x]
	return x
for i in l:
	checkNum[find(i)] = checkNum[find(i + 1)]
fin = ''
for i in range(len(n)):
	first = int(n[i])
	k = find(first)
	if k == first:
		fin += str(k)
	else:
		if k != 10:
			fin = str(k) + str(find(0)) * (len(n) - i - 1)
		else:
			fin = str(find(1)) + str(find(0)) * len(n)
		break
print(fin)


(N, K) = list(map(int, input().split()))
D = [int(x) for x in input().split()]
D = set(D)
kouho = N
while 1:
	lenkouho = len(str(kouho))
	flag = 1
	for i in range(lenkouho):
		if int(str(kouho)[i]) in D:
			flag = 0
	if flag == 1:
		print(kouho)
		break
	kouho += 1


import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):

	def assertIO(self, input, output):
		(stdout, stdin) = (sys.stdout, sys.stdin)
		(sys.stdout, sys.stdin) = (StringIO(), StringIO(input))
		resolve()
		sys.stdout.seek(0)
		out = sys.stdout.read()[:-1]
		(sys.stdout, sys.stdin) = (stdout, stdin)
		self.assertEqual(out, output)

	def test_入力例_1(self):
		input = '1000 8\n1 3 4 5 6 7 8 9'
		output = '2000'
		self.assertIO(input, output)

	def test_入力例_2(self):
		input = '9999 1\n0'
		output = '9999'
		self.assertIO(input, output)

def resolve():
	(N, K) = list(map(int, input().split()))
	D = list(input().split())
	for i in range(N, 10 * N + 1):
		for d in D:
			if str(i).count(d) != 0:
				break
		else:
			print(i)
			break

def __starting_point():
	resolve()
__starting_point()


(N, K) = map(int, input().split())
D = list(map(int, input().split()))
num = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
num = str(list(set(num) ^ set(D)))
ans = str(N)
clear = 0
while clear == 0:
	for i in range(len(ans)):
		if not ans[i] in num:
			break
		if i == len(ans) - 1:
			clear += 1
	ans = str(int(ans) + 1)
print(int(ans) - 1)


(N, K) = map(int, input().split())
D = list(input().split())
while True:
	n = str(N)
	for i in range(K):
		f = 0
		if D[i] in n:
			N += 1
			f = 1
			break
	if f == 0:
		break
print(N)


(N, K) = map(int, input().split())
hate_num = list(map(int, input().split()))
i = N
while 1:
	ans = list({int(i) for i in list(str(i))})
	for j in ans:
		if j in hate_num:
			break
	else:
		print(i)
		break
	i += 1


(n, k) = input().split()
d = list(map(int, input().split()))
a = []
for i in range(10):
	if i not in d:
		a.append(i)
n = list(map(int, list(n)))
for i in range(len(n)):
	if n[i] in d:
		ind = i
		done = False
		while not done:
			for j in range(n[ind] + 1, 10):
				if j in a:
					n[ind] = j
					done = True
					break
			if not done:
				ind -= 1
				if ind < 0:
					n.insert(0, a[1] if a[0] == 0 else a[0])
					ind = 0
					done = True
		for j in range(ind + 1, len(n)):
			n[j] = a[0]
		break
print(''.join(list(map(str, n))))


(n, k) = list(map(int, input().split()))
if k == 0:
	print(n)
	return
dislike = list(input().split())
ans = n - 1
flag = 1
while flag == 1:
	ans += 1
	flag = 0
	for i in str(ans):
		if i in dislike:
			flag = 1
			break
print(ans)


def testa(n, d):
	for i in d:
		if str(i) in str(n):
			return 0
	return 1
(n, k) = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]
while not testa(n, d):
	n += 1
print(n)


(N, K) = map(int, input().split())
bl = set(input().split())
while True:
	if len(set(str(N)) & bl) != 0:
		N += 1
	else:
		print(N)
		break


(N, K) = list(map(int, input().split()))
D = set(input().split())
for k in range(N, 10 ** 9):
	f = 1
	for e in str(k):
		if e in D:
			f = 0
			break
	if f == 1:
		print(k)
		return


def dfs(i, num_str):
	nonlocal ans_list
	if i == len(str(n)):
		ans_list.append(int(num_str))
		if len(num_list) == 1:
			ans_list.append(int(num_list[0] + num_str))
		elif num_list[0] == '0':
			ans_list.append(int(num_list[1] + num_str))
		else:
			ans_list.append(int(num_list[0] + num_str))
		return
	else:
		for j in num_list:
			dfs(i + 1, num_str + j)
(n, k) = map(int, input().split())
d = list(map(int, input().split()))
ans_list = []
num_list = []
for i in range(10):
	if i not in d:
		num_list.append(str(i))
dfs(0, '')
sort_list = sorted(ans_list)
for i in sort_list:
	if n <= i:
		print(int(i))
		break


(n, k) = map(int, input().split())
D = set(input())
for i in range(n, 10 ** 5):
	if set(str(i)) & D == set():
		print(i)
		return


i3 = lambda : map(int, input().split())
(N, K) = i3()
(*D,) = i3()
D = set(D)
for i in range(N, 10 ** 5):
	ans = 1
	for s in str(i):
		if int(s) in D:
			ans = 0
			break
	if ans:
		break
print(i)


import sys

def check(pay, like):
	str_pay = str(pay)
	like = ''.join(like)
	for p in str_pay:
		for lk in like:
			if p == lk:
				return False
	return True
(N, K) = list(map(int, input().split()))
D = []
D = list(map(int, input().split()))
str_D = []
for s in D:
	str_D.append(str(s))
pay = N
while True:
	if check(pay, str_D):
		print(pay)
		return
	pay += 1


(n, k) = list(map(int, input().split()))
d = list(input().split())
flag = True
while flag:
	flag2 = True
	for si in str(n):
		if si in d:
			n += 1
			flag2 = False
			break
	if flag2:
		break
	else:
		flag = True
print(n)


def check(n, D):
	N = []
	while n != 0:
		N.append(n % 10)
		n //= 10
	for d in D:
		if d in N:
			return False
	return True

def __starting_point():
	(n, k) = [int(x) for x in input().split(' ')]
	D = [int(x) for x in input().split(' ')]
	res = n
	while True:
		if check(res, D):
			break
		else:
			res += 1
	print(res)
__starting_point()


def is_dislike(N, ds):
	num = N
	while True:
		if num % 10 in ds:
			return True
		else:
			num = int(num / 10)
			if num == 0:
				break
	return False
nk = list(map(int, input().split()))
N = nk[0]
K = nk[1]
ds = list(map(int, input().split()))
while True:
	if is_dislike(N, ds):
		N = N + 1
	else:
		print(N)
		break


from math import gcd
from itertools import combinations, permutations, accumulate, product
from collections import deque, defaultdict, Counter
import decimal
import re
import math
import bisect
import heapq
import sys
sys.setrecursionlimit(10000000)
mod = 10 ** 9 + 7
INF = float('inf')
from sys import stdin
readline = stdin.readline

def readInts():
	return list(map(int, readline().split()))

def readTuples():
	return tuple(map(int, readline().split()))

def I():
	return int(readline())
(n, k) = readInts()
D = Counter(readInts())

def ok(n):
	while n:
		v = n % 10
		if D[v]:
			return False
		n //= 10
	return True
ans = n
for i in range(n, 100000):
	if ok(i):
		ans = i
		break
print(ans)


import sys
import numpy as np
read = sys.stdin.readline

def main(n, k, a):
	for i in range(n, 100000):
		s = np.array(list(map(int, str(i))), dtype=np.int64)
		ok = True
		for j in s:
			ok &= j not in a
		if ok:
			print(i)
			break

def __starting_point():
	(n, k) = np.fromstring(read(), dtype=np.int64, sep=' ')
	a = np.fromstring(read(), dtype=np.int64, sep=' ')
	main(n, k, a)
__starting_point()


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
inf = float('inf')
min_cost = inf
for amount in range(n, 100000):
	for (i, e) in enumerate(arr):
		if str(e) in str(amount):
			break
		if i == len(arr) - 1:
			min_cost = min(min_cost, amount)
print(min_cost)


(n, k) = input().split()
hate = list(input().split())
exi = True
t = True
while True:
	for c in hate:
		t = True
		if c in list(n):
			t = False
			break
	if t:
		print(n)
		break
	intN = int(n) + 1
	n = str(intN)


import itertools

def main():
	(N, K) = [int(n) for n in input().split(' ')]
	D = [1] * 10
	for d in input().split(' '):
		D[int(d)] = 0
	L = [str(i) for (i, v) in enumerate(D) if v == 1]
	digit = len(str(N))
	cand = []
	for n in list(itertools.product(L, repeat=digit)):
		p = int(''.join(list(n)))
		if p >= N:
			cand.append(p)
	if len(cand):
		print(min(cand))
	elif L[0] == '0':
		print(str(L[1]) + '0' * digit)
	else:
		print(str(L[0]) * (digit + 1))
main()


import sys
input = sys.stdin.readline

def find_ok(x, Oks):
	for i in Oks:
		if int(i) > int(x):
			break
	return i

def main():
	(n, k) = map(int, input().split())
	Nos = set(map(int, input().split()))
	while 1:
		x = str(n)
		set_n = set()
		for digit in x:
			set_n.add(int(digit))
		if len(set_n & Nos) == 0:
			break
		n += 1
	print(n)
main()


(n, k) = list(map(int, input().split()))
d = set(input().split())
while True:
	if len(set(str(n)) & d) != 0:
		n += 1
	else:
		print(n)
		break


(N, K) = map(int, input().split())
D = list(map(int, input().split()))
E = []
for i in range(10):
	if i not in D:
		E.append(i)
E = sorted(E)
N = str(N)
ind = len(N)
for i in range(len(N)):
	if int(N[i]) not in E:
		ind = i
		break
if ind == len(N):
	print(N)
else:
	flag = 0
	x = ''
	for i in range(ind, -1, -1):
		n = int(N[i])
		for e in E:
			if e > n:
				x = N[:i] + str(e) + str(E[0]) * (len(N) - i - 1)
				flag = 1
				break
		if flag == 1:
			break
	if flag == 0:
		if E[0] > 0:
			a = E[0]
		else:
			a = E[1]
		x = str(a) + str(E[0]) * len(N)
	print(x)


(n, k) = map(int, input().split())
ds = [d for d in input().split()]
while any((c in ds for c in str(n))):
	n += 1
print(n)


(n, k) = map(int, input().split())
d = list(input().split())
flg = True
while flg:
	flg = False
	m = list(str(n))
	for i in m:
		if i in d:
			flg = True
			break
	if flg:
		n += 1
print(n)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = set()
for i in range(10):
	if i in a:
		b.add(str(i))
while n > 0:
	c = set(list(str(n)))
	if c.isdisjoint(b):
		print(n)
		return
	n += 1


import sys

def resultSur97(x):
	return x % (10 ** 9 + 7)

def __starting_point():
	nk = list(map(int, input().split()))
	x = nk[1]
	dList = list(map(int, input().split()))
	f = 0
	n = nk[0]
	while f == 0:
		nList = [int(c) for c in str(n)]
		b = 1
		for i in nList:
			for j in dList:
				if i == j:
					b = 0
					break
		if b == 1:
			break
		else:
			n += 1
	print('{}'.format(n))
__starting_point()


import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque, Counter
from decimal import Decimal
import functools

def v():
	return input()

def k():
	return int(input())

def S():
	return input().split()

def I():
	return list(map(int, input().split()))

def X():
	return list(input())

def L():
	return list(input().split())

def l():
	return list(map(int, input().split()))

def lcm(a, b):
	return a * b // math.gcd(a, b)
sys.setrecursionlimit(10 ** 9)
mod = 10 ** 9 + 7
cnt = 0
ans = 0
inf = float('inf')
al = 'abcdefghijklmnopqrstuvwxyz'
AL = al.upper()
(n, k) = I()
d = l()
use = [i for i in range(11) if i not in d]
a = True
price = n
while a:
	cnt = 0
	for i in str(price):
		a = len(str(price))
		if int(i) not in d:
			cnt += 1
		else:
			cnt = inf
		if a == cnt:
			print(price)
			return
	price += 1


(n, k) = map(int, input().split())
d = list(map(str, input().split()))
e = set(d)
for i in range(n, 100001):
	v = set(str(i)) & e
	if len(v) == 0:
		print(i)
		return


import itertools
(n, k) = map(int, input().split())
d = list(map(int, input().split()))
safe = [i for i in range(10) if i not in d]
n_l = list(map(int, list(str(n))))
if len(set(safe) & set(n_l)) == len(set(n_l)):
	print(n)
	return
for v in itertools.product(safe, repeat=len(str(n))):
	if v[0] == 0:
		continue
	x = int(''.join(list(map(str, v))))
	if int(x) >= n:
		print(x)
		return
for v in itertools.product(safe, repeat=len(str(n)) + 1):
	if v[0] == 0:
		continue
	x = int(''.join(list(map(str, v))))
	if int(x) >= n:
		print(x)
		return


(N, K) = map(int, input().split())
D = set(input().split())
for i in range(N, 100001):
	for d in str(i):
		if d in D:
			break
	else:
		print(i)
		break


(n, k) = list(map(int, input().split()))
d = list(map(int, input().split()))
v = n
while True:
	f = True
	for t in list(str(v)):
		if int(t) in d:
			f = False
			continue
	if f:
		print(v)
		return
	v += 1


(n, k) = [int(x) for x in input().split()]
a = input().split()

def check(p):
	p = list(str(p))
	for i in range(len(p)):
		if p[i] in a:
			return False
	return True
for i in range(n, n * 10000):
	if check(i):
		print(i)
		break


(N, K) = map(int, input().split())
(*D,) = input().split()
ok = 1
while ok:
	ans = list(str(N))
	ok = 0
	for a in ans:
		if a in D:
			ok = 1
	N += 1
print(''.join(ans))


(n, k) = map(int, input().split())
D = list(map(int, input().split()))
for i in range(n, 100000):
	m = str(i)
	count = 0
	for j in range(len(m)):
		if int(m[j]) in D:
			break
		else:
			count += 1
		if count == len(m):
			print(i)
			return
print(0)


(n, k) = list(map(int, input().split()))
l = list(map(int, input().split()))
for v in range(n, 10 ** 5):
	for c in str(v):
		if int(c) in l:
			break
	else:
		print(v)
		return


(N, K) = map(int, input().split())
mat = input().split()
while True:
	FIN = 0
	for i in range(len(str(N))):
		for j in range(K):
			if mat[j] == str(N)[i]:
				FIN += 1
				break
	if FIN == 0:
		break
	else:
		N += 1
print(N)


(n, k) = [int(x) for x in input().split()]
ds = {int(x) for x in input().split()}
ns = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} - ds
temp = 0
d = {}
a = 1
b = {}
m = len(str(n)) + 1
over = False
while a <= m and (not over):
	c = []
	d = 10 ** (a - 1)
	for v in ns:
		if a > 1:
			for bv in b[a - 1]:
				t = v * d + bv
				c += [t]
				if t >= n:
					print(t)
					over = True
					break
			if over:
				break
		else:
			t = v * d
			c += [t]
			if t >= n:
				print(t)
				over = True
				break
	b[a] = c
	a += 1


(N, K) = map(int, input().split())
D = set(input().split())
E = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'} - D
result = False
while result == False:
	for i in str(N):
		if not i in E:
			N = N + 1
			result = False
			break
		else:
			result = True
print(N)


(n, k) = map(int, input().split())
a = list(input().split())
for i in range(n, 100001):
	flg = True
	s = str(i)
	for j in range(len(s)):
		if s[j] in a:
			flg = False
			break
	if flg:
		break
print(i)


import datetime
(n, k) = list(map(int, input().split()))
dislike = list(map(int, input().split()))
while True:
	for i in str(n):
		if int(i) not in dislike:
			continue
		else:
			break
	else:
		break
	n += 1
print(n)


(n, k) = list(map(int, input().split()))
d = list(map(int, input().split()))
for i in range(n, 10 ** 5):
	count = 0
	for j in range(k):
		u = str(d[j])
		if str(i).count(u) == 0:
			count += 1
	if count == k:
		print(i)
		break


def is_bad_nums(j: int, d: []) -> bool:
	while j:
		if j % 10 in d:
			return True
		j //= 10
	return False

def answer(n: int, k: int, d: []) -> int:
	for i in range(n, 100000):
		if is_bad_nums(i, d):
			continue
		return i

def main():
	(n, k) = map(int, input().split())
	d = list(map(int, input().split()))
	print(answer(n, k, d))

def __starting_point():
	main()
__starting_point()


(N, K) = map(int, input().split())
D = list(map(int, input().split()))
s = set(D)
for i in range(N, 10 ** 6 + 1):
	l = [j for j in str(i)]
	flag = True
	for n in l:
		if int(n) in s:
			flag = False
			break
	if flag:
		ans = i
		break
print(ans)


def price(N, K):
	Kn = input().split()
	Flag = False
	for i in range(N, 10 * N, 1):
		value = str(i)
		for j in range(K):
			if Kn[j] not in value:
				Flag = True
			elif Kn[j] in value:
				Flag = False
				break
		if Flag == True:
			print(i)
			break
(N, K) = (int(x) for x in input().split())
price(N, K)


(n, k) = list(map(int, input().split()))
dl = list(map(int, input().split()))
i = n
while True:
	money = list(map(int, str(i)))
	for m in money:
		if dl.count(m) != 0:
			break
	else:
		print(i)
		break
	i += 1


import sys
sys.setrecursionlimit(10 ** 7)
arr = ['a', 'b', 'c']
savelis = [0] * 10

def main():
	(N, K) = list(map(int, input().split()))
	Flis = list(map(int, input().split()))
	Tlis = [i for i in range(10)]
	Tlis = [i for i in Tlis if i not in Flis]
	str_flis = [str(i) for i in Flis]
	ANS = []
	for i in range(N * 10):
		stri = str(i)
		TF = True
		for j in stri:
			if j in str_flis:
				TF = False
				break
		if TF:
			ANS.append(i)
	for item in ANS:
		if item >= N:
			print(item)
			break

def __starting_point():
	main()
__starting_point()


(n, k) = list(map(int, input().split()))
a = list(input().split())
while not set(list(str(n)[0:k])).isdisjoint(a):
	n += 1
print(n)


(n, k) = map(int, input().split())
D = list(input().split())
ans = str(n)
while not all([c not in D for c in ans]) and int(ans) >= n:
	ans = str(int(ans) + 1)
print(ans)


(n, k) = map(int, input().split())
d = list(map(int, input().split()))
ng = [False] * 10
for i in d:
	ng[i] = True

def ok(n):
	nonlocal ng
	while n > 0:
		if ng[n % 10]:
			return False
		n //= 10
	return True
while not ok(n):
	n += 1
print(n)


(n, k) = list(map(int, input().split()))
d = set(map(int, input().split()))
while True:
	tmp_str = set(str(n))
	for i in tmp_str:
		if int(i) in d:
			n += 1
			break
	else:
		print(n)
		break


(n, k) = map(int, input().split())
d = list(map(int, input().split()))
x = list(range(1, 100001))
y = [0] * 100000
for i in range(100000):
	s = str(i)
	S = len(s)
	for j in range(S):
		if int(s[j]) in d:
			y[i - 1] = 1
			break
for i in range(100000):
	if i >= n - 1:
		if y[i] == 0:
			print(i + 1)
			break


(n, k) = map(int, input().split())
D = set(map(int, input().split()))
from itertools import count
for ans in count(n, 1):
	for c in str(ans):
		if int(c) in D:
			break
	else:
		print(ans)
		break


def iparse():
	return list(map(int, input().split()))
(n, k) = iparse()
d = iparse()
for i in range(n, 5000000):
	tmp = i
	f = True
	while tmp > 0:
		x = tmp % 10
		if x in d:
			f = False
			break
		tmp //= 10
	if f:
		print(i)
		return


from sys import stdin
input = stdin.readline
(N, K) = map(int, input().split())
D = set(map(int, input().split()))
while True:
	tmp = set(str(N))
	b = True
	for x in tmp:
		if int(x) in D:
			b = False
			break
	if b == True:
		break
	else:
		N += 1
print(N)


(N, K) = input().split()
D = list(map(int, input().split()))
ans = []
a = int(N[0])
x = 0
b = 0
while b in D:
	b += 1
c = 2
while c in D:
	c += 1
y = 0
while a == int(N[x]) and x <= len(N) - 1:
	while a in D and a <= 9:
		a += 1
	if a == 10:
		y = x
		if 0 in D:
			a += b
		if 1 in D:
			if b != 0:
				a += (b - 1) * 10
			else:
				a += (c - 1) * 10
	ans.append(str(a))
	if a != int(N[x]):
		for i in range(len(N) - 1 - x):
			ans.append(str(b))
	elif x <= len(N) - 2:
		x += 1
		a = int(N[x])
	else:
		a = int(N[x]) - 1
while y > 0:
	s = ans[y][0]
	t = ans[y][1]
	r = ans[y]
	ans[y] = t
	ans[y - 1] = str(int(ans[y - 1]) + 1)
	if int(ans[y - 1]) in D:
		u = int(ans[y - 1])
		while u in D:
			u += 1
			ans[y - 1] = str(u)
	if ans[y - 1] != '10':
		y = 0
	else:
		y -= 1
		ans[y] = r
print(''.join(ans))


(n, k) = map(int, input().split())
d = list(input().split())
num = [str(i) for i in range(10)]
for i in range(k):
	num.remove(d[i])
import itertools, heapq
ans = []
heapq.heapify(ans)
for i in itertools.product(num, repeat=len(str(n))):
	s = int(''.join(i))
	if s >= n:
		heapq.heappush(ans, s)
if len(ans) == 0:
	for i in itertools.product(num, repeat=len(str(n)) + 1):
		s = int(''.join(i))
		if s >= n:
			heapq.heappush(ans, s)
	print(heapq.heappop(ans))
else:
	print(heapq.heappop(ans))


(n, k) = list(map(int, input().split()))
d = list(map(int, input().split()))
s = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'} - set(str(d))
ans = n
while (s >= set(str(n))) == False:
	n += 1
	if (s >= set(str(n))) == True:
		ans = n
		break
print(ans)


def main():
	(N, K) = map(int, input().split())
	A_list = list(map(str, input().split()))
	use_list = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
	list_A = list(set(use_list) - set(A_list))
	for i in range(100000):
		ans = N + i
		ans_str = str(ans)
		frag = 0
		for val in ans_str:
			if str(val) in list_A:
				pass
			else:
				frag = 1
				break
		if frag == 0:
			break
	print(ans)

def __starting_point():
	main()
__starting_point()


def main():
	(N, K) = list(map(int, input().split()))
	D = set(map(int, input().split()))
	numset = set(range(0, 10))
	d = numset.difference(D)
	for n in range(N, pow(10, 6) + 10):
		check = set(list(str(n)))
		ngflag = False
		for i in check:
			if int(i) in D:
				ngflag = True
				break
		if not ngflag:
			break
	print(n)

def __starting_point():
	main()
__starting_point()


(N, K) = [int(x) for x in input().split()]
D = input().split()
for payment in range(N, 10 * N + 1):
	if all((char not in D for char in str(payment))):
		print(payment)
		break


(n, k) = map(int, input().split())
d = list(input().split())
num = [str(i) for i in range(10)]
for i in range(k):
	num.remove(d[i])
import itertools
ans = []
for i in itertools.product(num, repeat=len(str(n))):
	s = int(''.join(i))
	if s >= n:
		ans.append(s)
if len(ans) == 0:
	for i in itertools.product(num, repeat=len(str(n)) + 1):
		s = int(''.join(i))
		if s >= n:
			ans.append(s)
	print(min(ans))
else:
	print(min(ans))


(N, K) = map(int, input().split())
S = set(input().split())
while True:
	L = list(str(N))
	for i in L:
		if i in S:
			break
	else:
		break
	N += 1
print(N)


(N, K, *D) = list(map(int, open(0).read().split()))
D = set((str(d) for d in D))
for i in range(N, 100000):
	if set(str(i)) & D:
		continue
	print(i)
	break


(n, t) = [int(x) for x in input().split()]
d = [int(x) for x in input().split()]

def check(x) -> bool:
	while x > 0:
		a = x % 10
		if a in d:
			return False
		x //= 10
	return True
while check(n) == False:
	n += 1
print(n)


def minN(N: int, usable: list, restrict=True):
	usable.sort()
	keta = False
	if restrict:
		for i in usable:
			if i >= N:
				return str(i)
		return '1' + str(usable[0])
	else:
		return str(usable[0])

def rote(N: list, D: set, d: set):
	ans = []
	flag = True
	lenNstr = len(N)
	for (i, n) in enumerate(N):
		n = int(n)
		keta = 10 ** (len(N) - i - 1)
		if flag:
			if n in D:
				ans.append(int(minN(n, d)) * keta)
				flag = False
			else:
				ans.append(keta * n)
		else:
			ans.append(keta * min(d))
	return sum(ans)

def main():
	(N, K) = list(map(int, input().split()))
	D = set(map(int, input().split()))
	numset = set(range(0, 10))
	d = list(numset.difference(D))
	d.sort()
	for _ in range(10):
		Nstr = list(str(N))
		ans = rote(Nstr, D, d)
		N = ans
	print(ans)

def __starting_point():
	main()
__starting_point()


(N, K) = list(map(int, input().split()))
D = list(map(int, input().split()))

def ok(x):
	while x:
		if x % 10 in D:
			return False
		x //= 10
	return True
for i in range(N, 100000):
	if ok(i):
		print(i)
		return


(N, K) = map(int, input().split())
D = list(map(int, input().split()))
while True:
	S = str(N)
	flag = True
	for x in S:
		if int(x) in D:
			flag = False
	if flag == True:
		break
	N += 1
print(N)


(n, k) = map(int, input().split())
a = set(input().split())
while True:
	if not set(str(n)) & a:
		print(n)
		break
	n += 1


(N, K) = list(map(int, input().split()))
kirai = list(map(int, input().split()))
while True:
	bara = [int(x) for x in list(str(N))]
	diff = set(kirai) & set(bara)
	if diff == set():
		print(N)
		break
	else:
		N = N + 1