def main():

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

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



    while 1:

        f = 0

        hoge = str(n)

        for i in range(len(hoge)):

            for j in range(k):

                if(int(hoge[i]) == D[j]):

                    f = 1

                    break

                if f == 1:

                    break

            if f == 1:

                break

        if f == 0:

            print(n)

            break

        n += 1



if __name__ == "__main__":

    main()
def main():

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

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



    i = 0

    while True:

        S = str(N)

        f = True

        for s in S:

            if s in D:

                f = False

                break

        if f:

            break

        N += 1

    print(N)

    

if __name__ == "__main__":

    main()
def main():
    n, k = list(map(int, input().split()))
    D = list(map(int, input().split()))
    while 1:
        f = 0
        hoge = str(n)
        for i in range(len(hoge)):
            for j in range(k):
                if int(hoge[i]) == D[j]:
                    f = 1
                    break
                if f == 1:
                    break
            if f == 1:
                break
        if f == 0:
            print(n)
            break
        n += 1


if __name__ == "__main__":
    main()

def main():
    N, K = list(map(int, input().split()))
    D = list(input().split())
    i = 0
    while True:
        S = str(N)
        f = True
        for s in S:
            if s in D:
                f = False
                break
        if f:
            break
        N += 1
    print(N)


if __name__ == "__main__":
    main()

-    n, k = list(map(int, input().split())) -    D = list(map(int, input().split())) -    while 1: -        f = 0 -        hoge = str(n) -        for i in range(len(hoge)): -            for j in range(k): -                if int(hoge[i]) == D[j]: -                    f = 1 -                    break -                if f == 1: -                    break -            if f == 1: +    N, K = list(map(int, input().split())) +    D = list(input().split()) +    i = 0 +    while True: +        S = str(N) +        f = True +        for s in S: +            if s in D: +                f = False -        if f == 0: -            print(n) +        if f: -        n += 1 +        N += 1 +    print(N)