def inpl(): return input().split()

n, k = list(map(int, inpl()))

d = inpl()



x = n

while True:

    flg = True

    for c in str(x):

        if c in d:

            flg = False

            break

    if flg:

        break

    x += 1

print(x)
def main():

    import sys

    sys.setrecursionlimit(10 ** 7)



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

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



    digits = {x for x in range(10)}

    digits -= D

    # print(digits)

    digits = sorted(digits)



    def dfs(pay):

        if pay >= N:

            return pay



        np = pay * 10



        ret = 1 << 60

        if np == 0 and 0 in digits:

            for d in digits:

                if d == 0: continue

                ret = min(ret, dfs(np + d))

        else:

            for d in digits:

                ret = min(ret, dfs(np + d))

        return ret



    print((dfs(0)))





if __name__ == '__main__':

    main()

def inpl():
    return input().split()


n, k = list(map(int, inpl()))
d = inpl()
x = n
while True:
    flg = True
    for c in str(x):
        if c in d:
            flg = False
            break
    if flg:
        break
    x += 1
print(x)

def main():
    import sys

    sys.setrecursionlimit(10**7)
    N, K = list(map(int, input().split()))
    D = set(map(int, input().split()))
    digits = {x for x in range(10)}
    digits -= D
    # print(digits)
    digits = sorted(digits)

    def dfs(pay):
        if pay >= N:
            return pay
        np = pay * 10
        ret = 1 << 60
        if np == 0 and 0 in digits:
            for d in digits:
                if d == 0:
                    continue
                ret = min(ret, dfs(np + d))
        else:
            for d in digits:
                ret = min(ret, dfs(np + d))
        return ret

    print((dfs(0)))


if __name__ == "__main__":
    main()

-def inpl(): -    return input().split() +def main(): +    import sys + +    sys.setrecursionlimit(10**7) +    N, K = list(map(int, input().split())) +    D = set(map(int, input().split())) +    digits = {x for x in range(10)} +    digits -= D +    # print(digits) +    digits = sorted(digits) + +    def dfs(pay): +        if pay >= N: +            return pay +        np = pay * 10 +        ret = 1 << 60 +        if np == 0 and 0 in digits: +            for d in digits: +                if d == 0: +                    continue +                ret = min(ret, dfs(np + d)) +        else: +            for d in digits: +                ret = min(ret, dfs(np + d)) +        return ret + +    print((dfs(0))) -n, k = list(map(int, inpl())) -d = inpl() -x = n -while True: -    flg = True -    for c in str(x): -        if c in d: -            flg = False -            break -    if flg: -        break -    x += 1 -print(x) +if __name__ == "__main__": +    main()