from collections import deque



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

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

like=list(range(1,10))

dislike0=False



for s in D:

    if s==0:

        dislike0=True

    else:

        like.remove(s)



like.sort()

q=deque(like)



if dislike0==False:

    like.insert(0,0)



while q:

    num=q.popleft()



    if num>=N:

        print(num)

        exit()

    for i in range(len(like)):

        q.append((int(str(num)+str(like[i]))))
N,K=list(map(int,input().split()))

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



while True:

    for s in str(N):

        if s in D:

            N+=1

            break

    else:

        print(N)

        exit()
from collections import deque

N, K = list(map(int, input().split()))
D = list(map(int, input().split()))
like = list(range(1, 10))
dislike0 = False
for s in D:
    if s == 0:
        dislike0 = True
    else:
        like.remove(s)
like.sort()
q = deque(like)
if dislike0 == False:
    like.insert(0, 0)
while q:
    num = q.popleft()
    if num >= N:
        print(num)
        exit()
    for i in range(len(like)):
        q.append((int(str(num) + str(like[i]))))

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

-from collections import deque - -D = list(map(int, input().split())) -like = list(range(1, 10)) -dislike0 = False -for s in D: -    if s == 0: -        dislike0 = True +D = list(input().split()) +while True: +    for s in str(N): +        if s in D: +            N += 1 +            break -        like.remove(s) -like.sort() -q = deque(like) -if dislike0 == False: -    like.insert(0, 0) -while q: -    num = q.popleft() -    if num >= N: -        print(num) +        print(N) -    for i in range(len(like)): -        q.append((int(str(num) + str(like[i]))))