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

D = {i for i in range(10)} - set(map(int, input().split()))

for i in range(N, 100000):

    if all(j in D for j in map(int, str(i))):

        print(i)

        break

N, K, *D = list(map(int, open(0).read().split()))

D = set(str(d) for d in D)

for i in range(N, 100_000):

    if set(str(i)) & D:

        continue

    print(i)

    break

N, K = list(map(int, input().split()))
D = {i for i in range(10)} - set(map(int, input().split()))
for i in range(N, 100000):
    if all(j in D for j in map(int, str(i))):
        print(i)
        break

N, K, *D = list(map(int, open(0).read().split()))
D = set(str(d) for d in D)
for i in range(N, 100_000):
    if set(str(i)) & D:
        continue
    print(i)
    break

-N, K = list(map(int, input().split())) -D = {i for i in range(10)} - set(map(int, input().split())) -for i in range(N, 100000): -    if all(j in D for j in map(int, str(i))): -        print(i) -        break +N, K, *D = list(map(int, open(0).read().split())) +D = set(str(d) for d in D) +for i in range(N, 100_000): +    if set(str(i)) & D: +        continue +    print(i) +    break