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

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



for i in range(N, 100000):

    a = list(str(i))

    a = set(a)

    if a & D == set():

        print(i)

        break

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

D = set(list(input().split()))



while True:

    if set(list(str(N))) & D:

        N += 1

    else:

        print(N)

        exit()

N, K = list(map(int, input().split()))
D = set(map(str, input().split()))
for i in range(N, 100000):
    a = list(str(i))
    a = set(a)
    if a & D == set():
        print(i)
        break

N, K = list(map(int, input().split()))
D = set(list(input().split()))
while True:
    if set(list(str(N))) & D:
        N += 1
    else:
        print(N)
        exit()

-D = set(map(str, input().split())) -for i in range(N, 100000): -    a = list(str(i)) -    a = set(a) -    if a & D == set(): -        print(i) -        break +D = set(list(input().split())) +while True: +    if set(list(str(N))) & D: +        N += 1 +    else: +        print(N) +        exit()