#n=int(input())

ans=10**6

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

p=[int(i) for i in input().split()]

s=[]

for i in range(10):

    if i not in p:

        s.append(str(i))

        

for a in s+['0']:

    for b in s:

        for c in s:

            for d in s:

                for e in s:

                    x=list(map(int,[a+b+c+d+e,b+c+d+e,c+d+e,d+e,e]))

                    for i in x:

                        if i>=n:

                            ans=min(i,ans)

print(ans)

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

p=[int(i) for i in input().split()]

s=[]

for i in range(10):

    if i not in p:

        s.append(str(i))

    

for x in range(n,10*n):

    flg=True

    for d in str(x):

        if d not in s:

            flg=False

    if flg:

        print(x)

        break
# n=int(input())
ans = 10**6
n, k = list(map(int, input().split()))
p = [int(i) for i in input().split()]
s = []
for i in range(10):
    if i not in p:
        s.append(str(i))
for a in s + ["0"]:
    for b in s:
        for c in s:
            for d in s:
                for e in s:
                    x = list(
                        map(
                            int, [a + b + c + d + e, b + c + d + e, c + d + e, d + e, e]
                        )
                    )
                    for i in x:
                        if i >= n:
                            ans = min(i, ans)
print(ans)

n, k = list(map(int, input().split()))
p = [int(i) for i in input().split()]
s = []
for i in range(10):
    if i not in p:
        s.append(str(i))
for x in range(n, 10 * n):
    flg = True
    for d in str(x):
        if d not in s:
            flg = False
    if flg:
        print(x)
        break

-# n=int(input()) -ans = 10**6 -for a in s + ["0"]: -    for b in s: -        for c in s: -            for d in s: -                for e in s: -                    x = list( -                        map( -                            int, [a + b + c + d + e, b + c + d + e, c + d + e, d + e, e] -                        ) -                    ) -                    for i in x: -                        if i >= n: -                            ans = min(i, ans) -print(ans) +for x in range(n, 10 * n): +    flg = True +    for d in str(x): +        if d not in s: +            flg = False +    if flg: +        print(x) +        break