Num = [int(n) for n in input().rstrip().split()]



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



# numbers = [ n for n in range(10) if not n in D]



flag = 0



for i in range(Num[0],10*Num[0]+1):

    for j in str(i):

        if int(j) in D:

            flag = 1

            break



    if flag == 0:

        print(i)

        break

    else:

        flag =0 

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

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



flag = False



for i in range(N,100000):

    N = i

    while i > 0:

        flag = True

        if i%10 in D:

            flag = False

            break

        else:

            i //=10



    if flag == True:

        print(N)

        break

Num = [int(n) for n in input().rstrip().split()]
D = [int(n) for n in input().rstrip().split()]
# numbers = [ n for n in range(10) if not n in D]
flag = 0
for i in range(Num[0], 10 * Num[0] + 1):
    for j in str(i):
        if int(j) in D:
            flag = 1
            break
    if flag == 0:
        print(i)
        break
    else:
        flag = 0

N, K = list(map(int, input().split()))
D = [int(n) for n in input().split()]
flag = False
for i in range(N, 100000):
    N = i
    while i > 0:
        flag = True
        if i % 10 in D:
            flag = False
            break
        else:
            i //= 10
    if flag == True:
        print(N)
        break

-Num = [int(n) for n in input().rstrip().split()] -D = [int(n) for n in input().rstrip().split()] -# numbers = [ n for n in range(10) if not n in D] -flag = 0 -for i in range(Num[0], 10 * Num[0] + 1): -    for j in str(i): -        if int(j) in D: -            flag = 1 +N, K = list(map(int, input().split())) +D = [int(n) for n in input().split()] +flag = False +for i in range(N, 100000): +    N = i +    while i > 0: +        flag = True +        if i % 10 in D: +            flag = False -    if flag == 0: -        print(i) +        else: +            i //= 10 +    if flag == True: +        print(N) -    else: -        flag = 0