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

D = [int(i) for i in input().split()]



num = N

flag = True



while flag:

    for i in D:

        if str(i) in str(num):

            num += 1

            break

    else:

        print(num)

        flag = False

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

D = [str(i) for i in input().split()]

ans = N



for i in range(N, 100001):

    if set(list(str(i))) & set(D):

        gg = 1

    else:

        print(i)

        break
N, K = list(map(int, input().split()))
D = [int(i) for i in input().split()]
num = N
flag = True
while flag:
    for i in D:
        if str(i) in str(num):
            num += 1
            break
    else:
        print(num)
        flag = False

N, K = list(map(int, input().split()))
D = [str(i) for i in input().split()]
ans = N
for i in range(N, 100001):
    if set(list(str(i))) & set(D):
        gg = 1
    else:
        print(i)
        break

-D = [int(i) for i in input().split()] -num = N -flag = True -while flag: -    for i in D: -        if str(i) in str(num): -            num += 1 -            break +D = [str(i) for i in input().split()] +ans = N +for i in range(N, 100001): +    if set(list(str(i))) & set(D): +        gg = 1 -        print(num) -        flag = False +        print(i) +        break