

lst_1 = input().split()



N = lst_1[0]

K = int(lst_1[1])



lst_N = list(N)



lst_hate = input().split()



flg = True



while 1:



    for i in range(len(lst_N)):



        for j in range(len(lst_hate)):



            if lst_N[i] == lst_hate[j]:

                flg = False

                break



    if flg == True:

        break



    N = ''.join(lst_N)

    N = int(N)

    N += 1

    lst_N = list(str(N))



    flg = True



N = ''.join(lst_N)

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

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



k = N

"""while k > 0:

    lst.append(k % 10)

    k //= 10

#lst.reverse()"""

#print(lst)



while 1:

    flg = True

    lst = []

    N = k

    while k > 0:

        lst.append(k % 10)

        k //= 10

    lst.reverse()

    # print(lst)

    for i in range(len(lst)):

        if lst[i] in D:

            flg = False

            break

    if flg == False:

        k = N

        k += 1

    else:

        break

print(N)

lst_1 = input().split()
N = lst_1[0]
K = int(lst_1[1])
lst_N = list(N)
lst_hate = input().split()
flg = True
while 1:
    for i in range(len(lst_N)):
        for j in range(len(lst_hate)):
            if lst_N[i] == lst_hate[j]:
                flg = False
                break
    if flg == True:
        break
    N = "".join(lst_N)
    N = int(N)
    N += 1
    lst_N = list(str(N))
    flg = True
N = "".join(lst_N)
print(N)

N, K = list(map(int, input().split()))
D = list(map(int, input().split()))
k = N
"""while k > 0:
    lst.append(k % 10)
    k //= 10
#lst.reverse()"""
# print(lst)
while 1:
    flg = True
    lst = []
    N = k
    while k > 0:
        lst.append(k % 10)
        k //= 10
    lst.reverse()
    # print(lst)
    for i in range(len(lst)):
        if lst[i] in D:
            flg = False
            break
    if flg == False:
        k = N
        k += 1
    else:
        break
print(N)

-lst_1 = input().split() -N = lst_1[0] -K = int(lst_1[1]) -lst_N = list(N) -lst_hate = input().split() -flg = True +N, K = list(map(int, input().split())) +D = list(map(int, input().split())) +k = N +"""while k > 0: +    lst.append(k % 10) +    k //= 10 +#lst.reverse()""" +# print(lst) -    for i in range(len(lst_N)): -        for j in range(len(lst_hate)): -            if lst_N[i] == lst_hate[j]: -                flg = False -                break -    if flg == True: +    flg = True +    lst = [] +    N = k +    while k > 0: +        lst.append(k % 10) +        k //= 10 +    lst.reverse() +    # print(lst) +    for i in range(len(lst)): +        if lst[i] in D: +            flg = False +            break +    if flg == False: +        k = N +        k += 1 +    else: -    N = "".join(lst_N) -    N = int(N) -    N += 1 -    lst_N = list(str(N)) -    flg = True -N = "".join(lst_N)