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

Dset = set(input().split())

while True:

    if Dset & set(str(N)) == set():

        print(N)

        break

    else:

        N += 1

def check(num, ng):

    for c in str(num):

        if int(c) in ng:

            return False

    return True

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

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

while True:

    if check(N, D):

        print(N)

        break

    else:

        N += 1

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

def check(num, ng):
    for c in str(num):
        if int(c) in ng:
            return False
    return True


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

+def check(num, ng): +    for c in str(num): +        if int(c) in ng: +            return False +    return True + + -Dset = set(input().split()) +D = set(list(map(int, input().split()))) -    if Dset & set(str(N)) == set(): +    if check(N, D):