line1 = eval(input())

line2 = eval(input())

price, k = line1.split(" ")

num = line2.split(" ")

ans = ""



for i in range(int(price),100000):

    num2 = [str(x) for x in str(i)]

#     print(len(set(num)&set(num2)))

    if len(set(num)&set(num2))==0:

        print(i)

        break

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

d = set(input().split())

while True:

    if not set(str(n)) & d:

        print(n)

        break

    else:

        n += 1

        
line1 = eval(input())
line2 = eval(input())
price, k = line1.split(" ")
num = line2.split(" ")
ans = ""
for i in range(int(price), 100000):
    num2 = [str(x) for x in str(i)]
    #     print(len(set(num)&set(num2)))
    if len(set(num) & set(num2)) == 0:
        print(i)
        break

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

-line1 = eval(input()) -line2 = eval(input()) -price, k = line1.split(" ") -num = line2.split(" ") -ans = "" -for i in range(int(price), 100000): -    num2 = [str(x) for x in str(i)] -    #     print(len(set(num)&set(num2))) -    if len(set(num) & set(num2)) == 0: -        print(i) +n, k = list(map(int, input().split())) +d = set(input().split()) +while True: +    if not set(str(n)) & d: +        print(n) +    else: +        n += 1