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

d_array = [int(x) for x in input().split()]



for i in range(n, 100000):

    flag = True

    price = str(i)

    for d in d_array:

        str_d = str(d)

        if str_d in price:

            flag = False

    else:

        if flag:

            print(i)

            exit()



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

d_array = [str(x) for x in input().split()]

price = 0 

while True:

    flag = True

    for s in str(price):

        if s in d_array:

            flag = False

    if price >= n and flag:

        print(price)

        break

    price+=1
n, k = list(map(int, input().split()))
d_array = [int(x) for x in input().split()]
for i in range(n, 100000):
    flag = True
    price = str(i)
    for d in d_array:
        str_d = str(d)
        if str_d in price:
            flag = False
    else:
        if flag:
            print(i)
            exit()

n, k = list(map(int, input().split()))
d_array = [str(x) for x in input().split()]
price = 0
while True:
    flag = True
    for s in str(price):
        if s in d_array:
            flag = False
    if price >= n and flag:
        print(price)
        break
    price += 1

-d_array = [int(x) for x in input().split()] -for i in range(n, 100000): +d_array = [str(x) for x in input().split()] +price = 0 +while True: -    price = str(i) -    for d in d_array: -        str_d = str(d) -        if str_d in price: +    for s in str(price): +        if s in d_array: -    else: -        if flag: -            print(i) -            exit() +    if price >= n and flag: +        print(price) +        break +    price += 1