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

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



n = N



while True:

    for c in str(n):

        if c in D:

            break

    else:

        break

    n += 1



print(n)
import sys



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

D = [int(x) for x in input().split()]





def dfs(s: str, m: int) -> None:

    if s != "" and int(s) >= n:

        print(s)

        sys.exit()



    if len(s) == m:

        return



    for i in range(10):

        if i not in D:

            dfs(str(i) + s, m)





for i in range(sys.maxsize):

    dfs("", i)

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

import sys

n, k = list(map(int, input().split()))
D = [int(x) for x in input().split()]


def dfs(s: str, m: int) -> None:
    if s != "" and int(s) >= n:
        print(s)
        sys.exit()
    if len(s) == m:
        return
    for i in range(10):
        if i not in D:
            dfs(str(i) + s, m)


for i in range(sys.maxsize):
    dfs("", i)

-N, K = list(map(int, input().split())) -D = set(input().split()) -n = N -while True: -    for c in str(n): -        if c in D: -            break -    else: -        break -    n += 1 -print(n) +import sys + +n, k = list(map(int, input().split())) +D = [int(x) for x in input().split()] + + +def dfs(s: str, m: int) -> None: +    if s != "" and int(s) >= n: +        print(s) +        sys.exit() +    if len(s) == m: +        return +    for i in range(10): +        if i not in D: +            dfs(str(i) + s, m) + + +for i in range(sys.maxsize): +    dfs("", i)