Problem p04039 (python)

Fixed submission:
oldMoney, hateNumberLength = map(list, input().split())
hateLines = list(str(input()).rsplit(" "))
okLines = []
FirstBigList = []
newMoney = list(oldMoney)


def FindFirstBig(okLines, m, FirstBig):
    for i in okLines:
        if i > m:
            FirstBig.append(i)
    return FirstBig


for i in range(10):
    if str(i) not in hateLines:
        okLines.append(str(i))

FirstFlag = -1
ProblemFlag = -1
for index, m in enumerate(oldMoney):
    if FirstFlag == -1:
        if m in hateLines:
            FirstBigList = FindFirstBig(okLines, m, FirstBigList)
            if len(FirstBigList) > 0:
                newMoney[index] = FirstBigList[0]
                FirstFlag = index
            ProblemFlag = index
    elif FirstFlag != -1:
        newMoney[index] = okLines[0]

if oldMoney == newMoney:
    if ProblemFlag is not 0 and ProblemFlag is not -1:
        FirstBigList.clear()
        while ProblemFlag:
            FirstBigList = FindFirstBig(okLines, newMoney[ProblemFlag - 1], FirstBigList)
            if len(FirstBigList) > 0:
                newMoney[ProblemFlag - 1] = FirstBigList[0]
                for i in range(ProblemFlag, len(newMoney), 1):
                    newMoney[i] = okLines[0]
            if oldMoney == newMoney:
                ProblemFlag -= 1
    if ProblemFlag is 0:
        if okLines[0] != '0':
            newMoney.insert(0, okLines[0])
        else:
            newMoney.insert(0, okLines[1])
        for i in range(ProblemFlag + 1, len(newMoney), 1):
            newMoney[i] = okLines[0]
resultnew = "".join(newMoney)
print(resultnew)

Buggy submission (verdict: Runtime Error):
oldMoney, hateNumberLength = map(list, input().split())
hateLines = list(str(input()).rsplit(" "))
okLines = []
FirstBigList = []
newMoney = list(oldMoney)
def FindFirstBig(okLines,m,FirstBig):
    for i in okLines:
        if i > m:
            FirstBig.append(i)
    return FirstBig

for i in range(10):
    if str(i) not in hateLines:
        okLines.append(str(i))

FirstFlag = -1
ProblemFlag = -1
for index, m in enumerate(oldMoney):
    if FirstFlag == -1:
        if m in hateLines:
            FirstBigList = FindFirstBig(okLines,m,FirstBigList)
            if len(FirstBigList) > 0:
                newMoney[index] = FirstBigList[0]
                FirstFlag = index
            ProblemFlag = index
    elif FirstFlag != -1:
        newMoney[index] = okLines[0]

if oldMoney == newMoney:
    if ProblemFlag is not 0:
        FirstBigList.clear()
        while ProblemFlag:
            FirstBigList = FindFirstBig(okLines, newMoney[ProblemFlag - 1], FirstBigList)
            if len(FirstBigList) > 0:
                newMoney[ProblemFlag - 1] = FirstBigList[0]
                for i in range(ProblemFlag,len(newMoney),1):
                    newMoney[i] = okLines[0]
            if oldMoney == newMoney:
                ProblemFlag -= 1
    if ProblemFlag is 0:
        newMoney.insert(0,okLines[0])
        for i in range(ProblemFlag, len(newMoney), 1):
            newMoney[i] = okLines[0]
resultnew = "".join(newMoney)
print(resultnew)

Buggy submission (verdict: Runtime Error):
oldMoney, hateNumberLength = map(list, input().split())
hateLines = list(str(input()).rsplit(" "))
okLines = []
#newMoney = 0
for i in range(10):
    if str(i) not in hateLines and str(i) > oldMoney[0]:
        okLines.append(i)
for index,m in enumerate(oldMoney):
    if m in hateLines and okLines is not None:
        oldMoney[index] = str(okLines[0])
result = "".join(oldMoney)
print(result)

Buggy submission (verdict: Runtime Error):
oldMoney, hateNumberLength = map(list, input().split())
hateLines = list(str(input()).rsplit(" "))
okLines = []
newMoney = 0
for i in range(10):
    if str(i) not in hateLines and str(i) > oldMoney[0]:
        okLines.append(i)
for index,m in enumerate(oldMoney):
    if m in hateLines and okLines is not None:
        oldMoney[index] = okLines[0]
print("".join(oldMoney))