#!/usr/bin/env python3

import sys





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

    while True:

        for d in D:

            strn=str(N)

            if str(d) in strn:

                break

        else:

            print(N)

            return 

        N+=1



    return





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 = list(map(str,D))

    while True:

        for d in D:

            if d in str(N):

                N += 1

                break

        else:

            print(N)

            break



    return





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:
        for d in D:
            strn = str(N)
            if str(d) in strn:
                break
        else:
            print(N)
            return
        N += 1
    return


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 = list(map(str, D))
    while True:
        for d in D:
            if d in str(N):
                N += 1
                break
        else:
            print(N)
            break
    return


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()

+    D = list(map(str, D)) -            strn = str(N) -            if str(d) in strn: +            if d in str(N): +                N += 1 -            return -        N += 1 +            break