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

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



dr=len(d)

for i in range(N,100000):

    s=list(str(i))

    num=0

    for j in d:

        if(str(j) in s):

            break

        else:

            num+=1

    if(num==dr):

        print(i)

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

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



for i in range(N,100000):

        ans=True

        for j in str(i):

                if(str(j) in D):

                        ans=False

                        break

        if(ans):

                print(i)

                exit()

N, K = list(map(int, input().split()))
d = list(map(int, input().split()))
dr = len(d)
for i in range(N, 100000):
    s = list(str(i))
    num = 0
    for j in d:
        if str(j) in s:
            break
        else:
            num += 1
    if num == dr:
        print(i)
        break

N, K = list(map(int, input().split()))
D = list(input().split())
for i in range(N, 100000):
    ans = True
    for j in str(i):
        if str(j) in D:
            ans = False
            break
    if ans:
        print(i)
        exit()

-d = list(map(int, input().split())) -dr = len(d) +D = list(input().split()) -    s = list(str(i)) -    num = 0 -    for j in d: -        if str(j) in s: +    ans = True +    for j in str(i): +        if str(j) in D: +            ans = False -        else: -            num += 1 -    if num == dr: +    if ans: -        break +        exit()