n, k = list(map(int, input().split()))

d = list(map(str, input().split()))

digits = set(d)

num = {str(i) for i in range(0,10)}

left = num - digits

for i in range(n, 100000):

    Nums = set(str(i))

    if Nums <= left:

        print(i)

        break
n,k = input().split(" ")

l = input().split(" ")

l1 = ['0','1','2','3','4','5','6','7','8','9']

d = sorted(list(set(l1)-set(l)))

i = int(n)

while(True):

    if set(list(str(i))).difference(set(d))==set():

        break

    else:

        i+=1

print(i)
n, k = list(map(int, input().split()))
d = list(map(str, input().split()))
digits = set(d)
num = {str(i) for i in range(0, 10)}
left = num - digits
for i in range(n, 100000):
    Nums = set(str(i))
    if Nums <= left:
        print(i)
        break

n, k = input().split(" ")
l = input().split(" ")
l1 = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
d = sorted(list(set(l1) - set(l)))
i = int(n)
while True:
    if set(list(str(i))).difference(set(d)) == set():
        break
    else:
        i += 1
print(i)

-n, k = list(map(int, input().split())) -d = list(map(str, input().split())) -digits = set(d) -num = {str(i) for i in range(0, 10)} -left = num - digits -for i in range(n, 100000): -    Nums = set(str(i)) -    if Nums <= left: -        print(i) +n, k = input().split(" ") +l = input().split(" ") +l1 = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] +d = sorted(list(set(l1) - set(l))) +i = int(n) +while True: +    if set(list(str(i))).difference(set(d)) == set(): +    else: +        i += 1 +print(i)