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

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



while True:

    l = list(str(N))

    for x in l:

        if x in D:

            N += 1

            break

    else:

        print(N)

        exit()

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

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

safe = set(range(10)) - D



def test(N):

    return set((int(x) for x in str(N))) <= safe



def F(N):

    while N % 10:

        if test(N):

            return N

        N += 1

    N //= 10

    x = F(N)

    y = min(safe)

    return 10 * x + y



answer = F(N)

print(answer)



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

N, K = list(map(int, input().split()))
D = set(map(int, input().split()))
safe = set(range(10)) - D


def test(N):
    return set((int(x) for x in str(N))) <= safe


def F(N):
    while N % 10:
        if test(N):
            return N
        N += 1
    N //= 10
    x = F(N)
    y = min(safe)
    return 10 * x + y


answer = F(N)
print(answer)

-D = set(input().split()) -while True: -    l = list(str(N)) -    for x in l: -        if x in D: -            N += 1 -            break -    else: -        print(N) -        exit() +D = set(map(int, input().split())) +safe = set(range(10)) - D + + +def test(N): +    return set((int(x) for x in str(N))) <= safe + + +def F(N): +    while N % 10: +        if test(N): +            return N +        N += 1 +    N //= 10 +    x = F(N) +    y = min(safe) +    return 10 * x + y + + +answer = F(N) +print(answer)