n,k = list(map(int,input().split()))

d = list(input().split(' '))

def check(num):

    globals()

    s = str(n)

    for i in d:

        if i in s:

            return True

    return False

while(check(n)):

    n+=1

print(n)
def solve():

    n,k = list(map(int,input().split()))

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

    for i in range(n,100000):

        s = list(map(int,str(i)))

        flag = True

        for j in s:

            if j in d:

                flag = False

        if flag:

            print(i)

            return



if __name__ == "__main__":

    solve()
n, k = list(map(int, input().split()))
d = list(input().split(" "))


def check(num):
    globals()
    s = str(n)
    for i in d:
        if i in s:
            return True
    return False


while check(n):
    n += 1
print(n)

def solve():
    n, k = list(map(int, input().split()))
    d = set(map(int, input().split()))
    for i in range(n, 100000):
        s = list(map(int, str(i)))
        flag = True
        for j in s:
            if j in d:
                flag = False
        if flag:
            print(i)
            return


if __name__ == "__main__":
    solve()

-n, k = list(map(int, input().split())) -d = list(input().split(" ")) +def solve(): +    n, k = list(map(int, input().split())) +    d = set(map(int, input().split())) +    for i in range(n, 100000): +        s = list(map(int, str(i))) +        flag = True +        for j in s: +            if j in d: +                flag = False +        if flag: +            print(i) +            return -def check(num): -    globals() -    s = str(n) -    for i in d: -        if i in s: -            return True -    return False - - -while check(n): -    n += 1 -print(n) +if __name__ == "__main__": +    solve()