n,m = input().split()

k=int(n)

li = list(input().split())



for i in range(k,100000):

    for e in li:

        if e in str(i):

            break

    else:

        print(i)

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





digits = [0]*10

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



for i in digits_disliked:

    digits[i] = 1



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

    temp = i

    flag = True



    while(temp):

        rem = temp%10

        temp = temp//10

        if(digits[rem] != 0):

            flag = False

            break

    

    if(flag == True):

        print(i)

        break
n, m = input().split()
k = int(n)
li = list(input().split())
for i in range(k, 100000):
    for e in li:
        if e in str(i):
            break
    else:
        print(i)
        break

n, k = list(map(int, input().split()))
digits = [0] * 10
digits_disliked = list(map(int, input().split()))
for i in digits_disliked:
    digits[i] = 1
for i in range(n, 10**7 + 1):
    temp = i
    flag = True
    while temp:
        rem = temp % 10
        temp = temp // 10
        if digits[rem] != 0:
            flag = False
            break
    if flag == True:
        print(i)
        break

-n, m = input().split() -k = int(n) -li = list(input().split()) -for i in range(k, 100000): -    for e in li: -        if e in str(i): +n, k = list(map(int, input().split())) +digits = [0] * 10 +digits_disliked = list(map(int, input().split())) +for i in digits_disliked: +    digits[i] = 1 +for i in range(n, 10**7 + 1): +    temp = i +    flag = True +    while temp: +        rem = temp % 10 +        temp = temp // 10 +        if digits[rem] != 0: +            flag = False -    else: +    if flag == True: