Buggy python submission (verdict: Runtime Error):
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:
        ok_num.remove('0')
        print(ok_num[0].ljust(len(kingaku)+1, '0'))
        exit()

print(''.join(result))

Fixed submission:
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))

Buggy python submission (verdict: Runtime Error):
price, hate = input().split()
no_num = set([x for x in input().split()])
ok_num = sorted(list({'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'} - no_num))

result = []
f = True
exe = True
for i in price:
    f = True
    for j in ok_num:
        if i <= j:
            result.append(j)
            f = False
            break
    if f and exe:
        exe = False
        result[-1] = str(int(result[-1]) + 1)
        for i in ok_num:
            if result[-1] < i:
                result[-1] = i
                break
        result.append(ok_num[-1])

print(''.join(result))


Fixed submission:
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))

Buggy python submission (verdict: Runtime Error):
price, hate = input().split()
no_num = set([x for x in input().split()])
ok_num = sorted(list({'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'} - no_num))

result = []
f = True
exe = True
for i in price:
    f = True
    for j in ok_num:
        if i <= j:
            print(j)
            result.append(j)
            f = False
            break
    if f and exe:
        exe = False
        result[-1] = str(int(result[-1]) + 1)
        for i in ok_num:
            if result[-1] < i:
                result[-1] = i
                break
        result.append(ok_num[-1])

print(''.join(result))


Fixed submission:
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))

Buggy python submission (verdict: Runtime Error):
price, hate = input().split()
no_num = set([x for x in input().split()])
ok_num = sorted(list({'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'} - no_num))

result = []
f = True
exe = True
for i in price:
    f = True
    for j in ok_num:
        if i <= j:
            print(j)
            result.append(j)
            f = False
            break
    if f and exe:
        exe = False
        result[-1] = str(int(result[-1]) + 1)
        for i in ok_num:
            if result[-1] < i:
                result[-1] = i
                break
        result.append(ok_num[-1])
    

print(''.join(result))


Fixed submission:
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))