# encoding: utf-8

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

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



Db = []

for Di in range(10):

    if Di not in D: Db.append(Di)

# print("#", Db)



for level in range(6):

    if N // (10 ** level) < 1: break

# print("#", level)

    

memo = [None] * ((level + 1) * 10000)

    

def pay(pos, tmp):

    # print("##", pos, tmp)

    if pos > level or tmp >= N:

        if tmp >= N:

            # print("###", tmp)

            return tmp

        else: return 10000

    elif memo[pos * 10000 + tmp] != None: return memo[pos * 10000 + tmp]

    rets = []

    for Dbi in Db:

        add = Dbi * (10 ** pos)

        rets.append(pay(pos + 1, tmp + add))

    ret = min(rets)

    if memo[pos * 10000 + tmp] == None: memo[pos * 10000 + tmp] = ret    

    return ret



print((pay(0, 0)))
# encoding: utf-8

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

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



Db = []

for Di in range(10):

    if Di not in D: Db.append(Di)

# print("#", Db)



for level in range(6):

    if N // (10 ** level) < 1: break

# print("#", level)

    

# memo = [None] * ((level + 1) * 10000)

    

def pay(pos, tmp):

    # print("##", pos, tmp)

    if pos > level or tmp >= N:

        if tmp >= N:

            # print("###", tmp)

            return tmp

        else: return 10000

    # elif memo[pos * 10000 + tmp] != None: return memo[pos * 10000 + tmp]

    rets = []

    for Dbi in Db:

        add = Dbi * (10 ** pos)

        rets.append(pay(pos + 1, tmp + add))

    ret = min(rets)

    # if memo[pos * 10000 + tmp] == None: memo[pos * 10000 + tmp] = ret    

    return ret



print((pay(0, 0)))
# encoding: utf-8
N, K = list(map(int, input().split()))
D = list(map(int, input().split()))
Db = []
for Di in range(10):
    if Di not in D:
        Db.append(Di)
# print("#", Db)
for level in range(6):
    if N // (10**level) < 1:
        break
# print("#", level)
memo = [None] * ((level + 1) * 10000)


def pay(pos, tmp):
    # print("##", pos, tmp)
    if pos > level or tmp >= N:
        if tmp >= N:
            # print("###", tmp)
            return tmp
        else:
            return 10000
    elif memo[pos * 10000 + tmp] != None:
        return memo[pos * 10000 + tmp]
    rets = []
    for Dbi in Db:
        add = Dbi * (10**pos)
        rets.append(pay(pos + 1, tmp + add))
    ret = min(rets)
    if memo[pos * 10000 + tmp] == None:
        memo[pos * 10000 + tmp] = ret
    return ret


print((pay(0, 0)))

# encoding: utf-8
N, K = list(map(int, input().split()))
D = list(map(int, input().split()))
Db = []
for Di in range(10):
    if Di not in D:
        Db.append(Di)
# print("#", Db)
for level in range(6):
    if N // (10**level) < 1:
        break
# print("#", level)
# memo = [None] * ((level + 1) * 10000)
def pay(pos, tmp):
    # print("##", pos, tmp)
    if pos > level or tmp >= N:
        if tmp >= N:
            # print("###", tmp)
            return tmp
        else:
            return 10000
    # elif memo[pos * 10000 + tmp] != None: return memo[pos * 10000 + tmp]
    rets = []
    for Dbi in Db:
        add = Dbi * (10**pos)
        rets.append(pay(pos + 1, tmp + add))
    ret = min(rets)
    # if memo[pos * 10000 + tmp] == None: memo[pos * 10000 + tmp] = ret
    return ret


print((pay(0, 0)))

-memo = [None] * ((level + 1) * 10000) - - +# memo = [None] * ((level + 1) * 10000) -    elif memo[pos * 10000 + tmp] != None: -        return memo[pos * 10000 + tmp] +    # elif memo[pos * 10000 + tmp] != None: return memo[pos * 10000 + tmp] -    if memo[pos * 10000 + tmp] == None: -        memo[pos * 10000 + tmp] = ret +    # if memo[pos * 10000 + tmp] == None: memo[pos * 10000 + tmp] = ret