import sys

sys.setrecursionlimit(10 ** 5 + 10)

def input(): return sys.stdin.readline().strip()



def resolve():



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

    N= str(N)



    S={i for i in range(10)}

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

    D=S-D



    def search(N):

        for i in range(len(N)):

            if int(N[i]) not in D:

                return True

            elif i==len(N)-1:

                return False



    while True:

        if search(N) ==True:

            N=str(int(N)+1)

        else:

            print(N)

            break



















resolve()
import sys

sys.setrecursionlimit(10 ** 5 + 10)

def input(): return sys.stdin.readline().strip()



def resolve():



    def main():

        

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

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



        L={i for i in range(10)}

        U=L-D

        while True:



            sn = str(N)

            ln = len(sn)



            for i in range(ln):

                if int(sn[i]) not in U:

                    N+=1

                    break

                elif i==ln-1:

                    return int(N)

    print((main()))







resolve()
import sys

sys.setrecursionlimit(10**5 + 10)


def input():
    return sys.stdin.readline().strip()


def resolve():
    N, K = list(map(int, input().split()))
    N = str(N)
    S = {i for i in range(10)}
    D = set(map(int, input().split()))
    D = S - D

    def search(N):
        for i in range(len(N)):
            if int(N[i]) not in D:
                return True
            elif i == len(N) - 1:
                return False

    while True:
        if search(N) == True:
            N = str(int(N) + 1)
        else:
            print(N)
            break


resolve()

import sys

sys.setrecursionlimit(10**5 + 10)


def input():
    return sys.stdin.readline().strip()


def resolve():
    def main():
        N, K = list(map(int, input().split()))
        D = set(map(int, input().split()))
        L = {i for i in range(10)}
        U = L - D
        while True:
            sn = str(N)
            ln = len(sn)
            for i in range(ln):
                if int(sn[i]) not in U:
                    N += 1
                    break
                elif i == ln - 1:
                    return int(N)

    print((main()))


resolve()

-    N, K = list(map(int, input().split())) -    N = str(N) -    S = {i for i in range(10)} -    D = set(map(int, input().split())) -    D = S - D +    def main(): +        N, K = list(map(int, input().split())) +        D = set(map(int, input().split())) +        L = {i for i in range(10)} +        U = L - D +        while True: +            sn = str(N) +            ln = len(sn) +            for i in range(ln): +                if int(sn[i]) not in U: +                    N += 1 +                    break +                elif i == ln - 1: +                    return int(N) -    def search(N): -        for i in range(len(N)): -            if int(N[i]) not in D: -                return True -            elif i == len(N) - 1: -                return False - -    while True: -        if search(N) == True: -            N = str(int(N) + 1) -        else: -            print(N) -            break +    print((main()))