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

d = input().split()

while len(set(str(n)) & set(d)) != 0:

  n += 1

print(n)
n=int(input().split()[0])

d=set(eval(input()))

while len(set(str(n))&d):

  n+=1

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

n = int(input().split()[0])
d = set(eval(input()))
while len(set(str(n)) & d):
    n += 1
print(n)

-n, k = list(map(int, input().split())) -d = input().split() -while len(set(str(n)) & set(d)) != 0: +n = int(input().split()[0]) +d = set(eval(input())) +while len(set(str(n)) & d):