numbers = {str(i) for i in range(10)}

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

*D, = list(map(str, input().split()))

D = set(D)

available = numbers - D

ans = 0

for i in range(N, 100000):

    nums = set(str(i))

    if nums <= available:

        print(i)

        break

def problem_c():

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

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

    numbers = {str(i) for i in range(10)}

    availables = set(numbers) - set(D)



    for i in range(N, 100000):

        nums = set(str(i))

        if nums <= availables:

            print(i)

            return



##########

problem_c()

numbers = {str(i) for i in range(10)}
N, K = list(map(int, input().split()))
(*D,) = list(map(str, input().split()))
D = set(D)
available = numbers - D
ans = 0
for i in range(N, 100000):
    nums = set(str(i))
    if nums <= available:
        print(i)
        break

def problem_c():
    N, K = list(map(int, input().split()))
    D = list(map(str, input().split()))
    numbers = {str(i) for i in range(10)}
    availables = set(numbers) - set(D)
    for i in range(N, 100000):
        nums = set(str(i))
        if nums <= availables:
            print(i)
            return


##########
problem_c()

-numbers = {str(i) for i in range(10)} -N, K = list(map(int, input().split())) -(*D,) = list(map(str, input().split())) -D = set(D) -available = numbers - D -ans = 0 -for i in range(N, 100000): -    nums = set(str(i)) -    if nums <= available: -        print(i) -        break +def problem_c(): +    N, K = list(map(int, input().split())) +    D = list(map(str, input().split())) +    numbers = {str(i) for i in range(10)} +    availables = set(numbers) - set(D) +    for i in range(N, 100000): +        nums = set(str(i)) +        if nums <= availables: +            print(i) +            return + + +########## +problem_c()