kingaku, n = input().split()

no_num = input().split()

result = []

ok_num = []

kuriage_num = [-1, 0]



def kuriage(l):

    for i in ok_num:

        if result[l] < i:

            kuriage_num = [l, i]

            return

    if l <= 0:

        return

    return kuriage(l-1)



#使える数字のリストを作成

for i in range(10):

    if not str(i) in no_num:

        ok_num.append(str(i))



set_flg = False

for i in kingaku:

    set_flg = True

    for j in ok_num:

        if i == j:

            set_flg = False

            result.append(j)

            break

        elif i < j:

            result.append(j)

            print(("".join(result).ljust(len(kingaku), ok_num[0])))

            exit()

            break

    

    if set_flg:

        n = 0

        if ok_num[0] == '0':

            n = 1

        print((ok_num[n].ljust(len(kingaku)+1, ok_num[0])))

        exit()



print((''.join(result)))

kingaku, n = input().split()

no_num = input().split()

ok_num = []

result = []



for i in range(10):

    if not str(i) in no_num:

        ok_num.append(str(i))



set_flg = False

for i in kingaku:

    set_flg = True

    for j in ok_num:

        if i == j:

            set_flg = False

            result.append(j)

            break

        elif i < j:

            result.append(j)

            print(("".join(result).ljust(len(kingaku), ok_num[0])))

            exit()

            break

    

    if set_flg:

        n = 0

        if ok_num[0] == '0':

            n = 1

        print((ok_num[n].ljust(len(kingaku)+1, ok_num[0])))

        exit()



print((''.join(result)))
kingaku, n = input().split()
no_num = input().split()
result = []
ok_num = []
kuriage_num = [-1, 0]


def kuriage(l):
    for i in ok_num:
        if result[l] < i:
            kuriage_num = [l, i]
            return
    if l <= 0:
        return
    return kuriage(l - 1)


# 使える数字のリストを作成
for i in range(10):
    if not str(i) in no_num:
        ok_num.append(str(i))
set_flg = False
for i in kingaku:
    set_flg = True
    for j in ok_num:
        if i == j:
            set_flg = False
            result.append(j)
            break
        elif i < j:
            result.append(j)
            print(("".join(result).ljust(len(kingaku), ok_num[0])))
            exit()
            break
    if set_flg:
        n = 0
        if ok_num[0] == "0":
            n = 1
        print((ok_num[n].ljust(len(kingaku) + 1, ok_num[0])))
        exit()
print(("".join(result)))

kingaku, n = input().split()
no_num = input().split()
ok_num = []
result = []
for i in range(10):
    if not str(i) in no_num:
        ok_num.append(str(i))
set_flg = False
for i in kingaku:
    set_flg = True
    for j in ok_num:
        if i == j:
            set_flg = False
            result.append(j)
            break
        elif i < j:
            result.append(j)
            print(("".join(result).ljust(len(kingaku), ok_num[0])))
            exit()
            break
    if set_flg:
        n = 0
        if ok_num[0] == "0":
            n = 1
        print((ok_num[n].ljust(len(kingaku) + 1, ok_num[0])))
        exit()
print(("".join(result)))

+ok_num = [] -ok_num = [] -kuriage_num = [-1, 0] - - -def kuriage(l): -    for i in ok_num: -        if result[l] < i: -            kuriage_num = [l, i] -            return -    if l <= 0: -        return -    return kuriage(l - 1) - - -# 使える数字のリストを作成