def C_IrohasObsession():

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

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

    ans = 0

    for x in range(N, 100000):

        for y in str(x):

            if int(y) in D:

                break

        else:

            ans = int(x)

            break

    print(ans)



if __name__ == "__main__":

    C_IrohasObsession()
def C_IrohasObsession():

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

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

    ans = 0

    for x in range(N, 10000):

        for y in str(x):

            if int(y) in D:

                break

        else:

            ans = int(x)

            break

    if N > ans:

        for x in range(1,10):

            if x not in D:

                ans = x * 10000

                if 0 in D:

                    ans += x * 1000 + x * 100 + x * 10 + x

                break

    print(ans)



if __name__ == "__main__":

    C_IrohasObsession()
def C_IrohasObsession():
    N, K = list(map(int, input().split()))
    D = list(map(int, input().split()))
    ans = 0
    for x in range(N, 100000):
        for y in str(x):
            if int(y) in D:
                break
        else:
            ans = int(x)
            break
    print(ans)


if __name__ == "__main__":
    C_IrohasObsession()

def C_IrohasObsession():
    N, K = list(map(int, input().split()))
    D = list(map(int, input().split()))
    ans = 0
    for x in range(N, 10000):
        for y in str(x):
            if int(y) in D:
                break
        else:
            ans = int(x)
            break
    if N > ans:
        for x in range(1, 10):
            if x not in D:
                ans = x * 10000
                if 0 in D:
                    ans += x * 1000 + x * 100 + x * 10 + x
                break
    print(ans)


if __name__ == "__main__":
    C_IrohasObsession()

-    for x in range(N, 100000): +    for x in range(N, 10000): +    if N > ans: +        for x in range(1, 10): +            if x not in D: +                ans = x * 10000 +                if 0 in D: +                    ans += x * 1000 + x * 100 + x * 10 + x +                break