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

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

a=[]

for i in range(10):

    sum=0

    for x in d:

        if x==i:

            break

        else:

            sum+=1

    if sum==k:

        a.append(i)

a=set(a)

for i in range(n,10*n+1):

    b=[]

    x=len(str(i))

    y=str(i)

    for j in range(x):

        b.append(int(y[j]))

    b=set(b)

    if a>=b:

        print(i)

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

d=set(input().split())



while len(d&set(str(n)))!=0:

    n+=1

print(n)
n, k = list(map(int, input().split()))
d = list(map(int, input().split()))
a = []
for i in range(10):
    sum = 0
    for x in d:
        if x == i:
            break
        else:
            sum += 1
    if sum == k:
        a.append(i)
a = set(a)
for i in range(n, 10 * n + 1):
    b = []
    x = len(str(i))
    y = str(i)
    for j in range(x):
        b.append(int(y[j]))
    b = set(b)
    if a >= b:
        print(i)
        break

n, k = list(map(int, input().split()))
d = set(input().split())
while len(d & set(str(n))) != 0:
    n += 1
print(n)

-d = list(map(int, input().split())) -a = [] -for i in range(10): -    sum = 0 -    for x in d: -        if x == i: -            break -        else: -            sum += 1 -    if sum == k: -        a.append(i) -a = set(a) -for i in range(n, 10 * n + 1): -    b = [] -    x = len(str(i)) -    y = str(i) -    for j in range(x): -        b.append(int(y[j])) -    b = set(b) -    if a >= b: -        print(i) -        break +d = set(input().split()) +while len(d & set(str(n))) != 0: +    n += 1 +print(n)