import sys

from bisect import bisect_left

def input(): return sys.stdin.readline().strip()



def main():

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

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

    while True:

        check = True

        for c in str(N):

            if int(c) in D:

                check = False

        if check:

            print(N)

            return

        N += 1





if __name__ == "__main__":

    main()

import sys

from itertools import product

def input(): return sys.stdin.readline().strip()



def main():

    """

    itertools.productを使うと高速なようなので写経

    参考：https://atcoder.jp/contests/abc042/submissions/16188969

    """

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

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

    ok = [i for i in range(10) if i not in D]

    l = len(str(N))

    if int(str(ok[-1]) * l) < N:

        if ok[0] == 0:

            print((ok[1] * 10 ** l))

        else:

            print((str(ok[0]) * (l + 1)))

    else:

        for x in product(ok, repeat=l):

            x = int("".join(map(str, x)))

            if x >= N:

                print(x)

                return







if __name__ == "__main__":

    main()

import sys
from bisect import bisect_left


def input():
    return sys.stdin.readline().strip()


def main():
    N, K = list(map(int, input().split()))
    D = set(map(int, input().split()))
    while True:
        check = True
        for c in str(N):
            if int(c) in D:
                check = False
        if check:
            print(N)
            return
        N += 1


if __name__ == "__main__":
    main()

import sys
from itertools import product


def input():
    return sys.stdin.readline().strip()


def main():
    """
    itertools.productを使うと高速なようなので写経
    参考：https://atcoder.jp/contests/abc042/submissions/16188969
    """
    N, K = list(map(int, input().split()))
    D = set(map(int, input().split()))
    ok = [i for i in range(10) if i not in D]
    l = len(str(N))
    if int(str(ok[-1]) * l) < N:
        if ok[0] == 0:
            print((ok[1] * 10**l))
        else:
            print((str(ok[0]) * (l + 1)))
    else:
        for x in product(ok, repeat=l):
            x = int("".join(map(str, x)))
            if x >= N:
                print(x)
                return


if __name__ == "__main__":
    main()

-from bisect import bisect_left +from itertools import product +    """ +    itertools.productを使うと高速なようなので写経 +    参考：https://atcoder.jp/contests/abc042/submissions/16188969 +    """ -    while True: -        check = True -        for c in str(N): -            if int(c) in D: -                check = False -        if check: -            print(N) -            return -        N += 1 +    ok = [i for i in range(10) if i not in D] +    l = len(str(N)) +    if int(str(ok[-1]) * l) < N: +        if ok[0] == 0: +            print((ok[1] * 10**l)) +        else: +            print((str(ok[0]) * (l + 1))) +    else: +        for x in product(ok, repeat=l): +            x = int("".join(map(str, x))) +            if x >= N: +                print(x) +                return