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(input().split())



    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(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(input().split())
    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()

-    i = 0