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

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



n = N

while True:

    s = str(n)

    S = set(list(s))

    for c in S:

        if c in D:

            break

    else:

        break

    n += 1

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

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



def check(x):

    for c in str(x):

        if c in D: return False

    return True



ans = N

while not check(ans): ans += 1

print(ans)
N, K = list(map(int, input().split()))
D = list(map(str, list(map(int, input().split()))))
n = N
while True:
    s = str(n)
    S = set(list(s))
    for c in S:
        if c in D:
            break
    else:
        break
    n += 1
print(n)

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


def check(x):
    for c in str(x):
        if c in D:
            return False
    return True


ans = N
while not check(ans):
    ans += 1
print(ans)

-D = list(map(str, list(map(int, input().split())))) -n = N -while True: -    s = str(n) -    S = set(list(s)) -    for c in S: +D = set(input().split()) + + +def check(x): +    for c in str(x): -            break -    else: -        break -    n += 1 -print(n) +            return False +    return True + + +ans = N +while not check(ans): +    ans += 1 +print(ans)