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

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



while True:

    flag = 1

    N_str = list(str(N))

    

    for s in N_str:

        if int(s) in D:

            flag = 0

            break

    

    if flag:

        print(N)

        break

    

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

D = set(list(map(int, input().split())))



ans = 0



for i in range(N, 10*N+1):

    res = i

    while res > 0:

        digit = res % 10

        

        if digit in D:

            break

        

        res //= 10

        

    if res <= 0:

        ans = i   

        break



print(ans)
N, K = list(map(int, input().split()))
D = list(map(int, input().split()))
while True:
    flag = 1
    N_str = list(str(N))
    for s in N_str:
        if int(s) in D:
            flag = 0
            break
    if flag:
        print(N)
        break
    N += 1

N, K = list(map(int, input().split()))
D = set(list(map(int, input().split())))
ans = 0
for i in range(N, 10 * N + 1):
    res = i
    while res > 0:
        digit = res % 10
        if digit in D:
            break
        res //= 10
    if res <= 0:
        ans = i
        break
print(ans)

-D = list(map(int, input().split())) -while True: -    flag = 1 -    N_str = list(str(N)) -    for s in N_str: -        if int(s) in D: -            flag = 0 +D = set(list(map(int, input().split()))) +ans = 0 +for i in range(N, 10 * N + 1): +    res = i +    while res > 0: +        digit = res % 10 +        if digit in D: -    if flag: -        print(N) +        res //= 10 +    if res <= 0: +        ans = i -    N += 1 +print(ans)