n,k = list(map(int,input().split()))

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



ans = n

while True:

    for i in list(map(int, str(ans))):

        if i in D:

            break

    else:

        print (ans)

        exit ()



    ans += 1

import sys

sys.setrecursionlimit(500000)



n,k = list(map(int,input().split()))

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



ans = []

def dfs(p:str):

    if int(p)>=n:

        ans.append(int(p))

        return



    if len(p)>len(str(n))+1:

        return



    for i in range(10):

        if not i in D:

            dfs(p+str(i))



for i in range(10):

    if not i in D:

        dfs(str(i))



print((min(ans)))

n, k = list(map(int, input().split()))
D = list(map(int, input().split()))
ans = n
while True:
    for i in list(map(int, str(ans))):
        if i in D:
            break
    else:
        print(ans)
        exit()
    ans += 1

import sys

sys.setrecursionlimit(500000)
n, k = list(map(int, input().split()))
D = list(map(int, input().split()))
ans = []


def dfs(p: str):
    if int(p) >= n:
        ans.append(int(p))
        return
    if len(p) > len(str(n)) + 1:
        return
    for i in range(10):
        if not i in D:
            dfs(p + str(i))


for i in range(10):
    if not i in D:
        dfs(str(i))
print((min(ans)))

+import sys + +sys.setrecursionlimit(500000) -ans = n -while True: -    for i in list(map(int, str(ans))): -        if i in D: -            break -    else: -        print(ans) -        exit() -    ans += 1 +ans = [] + + +def dfs(p: str): +    if int(p) >= n: +        ans.append(int(p)) +        return +    if len(p) > len(str(n)) + 1: +        return +    for i in range(10): +        if not i in D: +            dfs(p + str(i)) + + +for i in range(10): +    if not i in D: +        dfs(str(i)) +print((min(ans)))