Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K.  She is shopping, and now paying at the cashier. Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change).  However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.  Find the amount of money that she will hand to the cashier.
import math

def ceil(n, i):
    dec = 10 ** i
    return n // dec * dec
def floor(n, i):
    dec = 10 ** i
    return n // dec * dec + dec

(n, k) = list(map(int, input().split()))
d = list(map(int, input().split()))
l = []

for i in range(0, 10):
    if i not in d:
        l.append(i)
for i in range(1, len(str(n)) + 1):
    nown = n // (10 ** (i - 1)) % 10
    ok = False
    print(nown)
    for j in l:
        if j == nown:
            ok = True
            break
        elif j > nown:
            ok = True
            n = ceil(n, i)
            print(str(j) + str(l[0]) * (i - 1))
            n += int(str(j) + str(l[0]) * (i - 1))
            break
    if not (ok):
        n = floor(n, i)
        n += int(str(l[0]) * i)
        
print(n)



def ceil(n, i):
    dec = 10 ** i
    return n // dec * dec

(n, k) = list(map(int, input().split()))
d = list(map(int, input().split()))
l = []
for i in range(0, 10):
    if i not in d:
        l.append(i)
i = 1
while len(str(n)) >= i:
    nown = n // (10 ** (i - 1)) % 10
    ok = False
    for j in l:
        if j == nown:
            ok = True
            break
        elif j > nown:
            ok = True
            n = ceil(n, i)
            n += int(str(j) + str(l[0]) * (i - 1))
            break
    if not (ok):
        n = ceil(n, i) + 10 ** i
        n += int(str(l[0]) * i)
    i += 1
print(n)