#!/usr/bin/env python3

import sys





def solve(N: int, K: int, D: "List[int]"):

    

    while(True):

        nl = list(map(int,list(str(N))))

        f = True

        for i in range(len(nl)):

            if(nl[i] in D):

                f = False

        if(f):

            print(N)

            exit()

        else:

            N += 1



    return





# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)

def main():

    def iterate_tokens():

        for line in sys.stdin:

            for word in line.split():

                yield word

    tokens = iterate_tokens()

    N = int(next(tokens))  # type: int

    K = int(next(tokens))  # type: int

    D = [int(next(tokens)) for _ in range(K)]  # type: "List[int]"

    solve(N, K, D)



if __name__ == '__main__':

    main()

#!/usr/bin/env python3

import sys





def solve(N: int, K: int, D: "List[int]"):

    d = set(map(str, D))

    while set(str(N))&d:

        N += 1



    print(N)



    return





# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)

def main():

    def iterate_tokens():

        for line in sys.stdin:

            for word in line.split():

                yield word

    tokens = iterate_tokens()

    N = int(next(tokens))  # type: int

    K = int(next(tokens))  # type: int

    D = [int(next(tokens)) for _ in range(K)]  # type: "List[int]"

    solve(N, K, D)



if __name__ == '__main__':

    main()

#!/usr/bin/env python3
import sys


def solve(N: int, K: int, D: "List[int]"):
    while True:
        nl = list(map(int, list(str(N))))
        f = True
        for i in range(len(nl)):
            if nl[i] in D:
                f = False
        if f:
            print(N)
            exit()
        else:
            N += 1
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    D = [int(next(tokens)) for _ in range(K)]  # type: "List[int]"
    solve(N, K, D)


if __name__ == "__main__":
    main()

#!/usr/bin/env python3
import sys


def solve(N: int, K: int, D: "List[int]"):
    d = set(map(str, D))
    while set(str(N)) & d:
        N += 1
    print(N)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    D = [int(next(tokens)) for _ in range(K)]  # type: "List[int]"
    solve(N, K, D)


if __name__ == "__main__":
    main()

-    while True: -        nl = list(map(int, list(str(N)))) -        f = True -        for i in range(len(nl)): -            if nl[i] in D: -                f = False -        if f: -            print(N) -            exit() -        else: -            N += 1 +    d = set(map(str, D)) +    while set(str(N)) & d: +        N += 1 +    print(N)