import sys, math



def input():

    return sys.stdin.readline()[:-1]



def main():

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

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

    for k in range(N,100001):

        s = str(k)

        f = 0

        for e in s:

            if e in D:

                f = 1

                break

        if f == 0:

            print(s)

            exit(0)



if __name__ == '__main__':

    main()

import sys, math



def input():

    return sys.stdin.readline()[:-1]



def main():

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

    D = set(input().split())

    for ans in range(N,1000000):

        f = 0

        for e in str(ans):

            if e in D:

                f = 1

                break

        if f == 0:

            print(ans)

            exit(0)

if __name__ == '__main__':

    main()

import sys, math


def input():
    return sys.stdin.readline()[:-1]


def main():
    N, K = list(map(int, input().split()))
    D = set(list(input().split()))
    for k in range(N, 100001):
        s = str(k)
        f = 0
        for e in s:
            if e in D:
                f = 1
                break
        if f == 0:
            print(s)
            exit(0)


if __name__ == "__main__":
    main()

import sys, math


def input():
    return sys.stdin.readline()[:-1]


def main():
    N, K = list(map(int, input().split()))
    D = set(input().split())
    for ans in range(N, 1000000):
        f = 0
        for e in str(ans):
            if e in D:
                f = 1
                break
        if f == 0:
            print(ans)
            exit(0)


if __name__ == "__main__":
    main()

-    D = set(list(input().split())) -    for k in range(N, 100001): -        s = str(k) +    D = set(input().split()) +    for ans in range(N, 1000000): -        for e in s: +        for e in str(ans): -            print(s) +            print(ans)