graph = {1:[], 2:[1], 3:[1], 4:[2], 5[1], 6:[2,3], 7:[1], 8:[4], 9:[3], 10:[2,5]}

def toposort(graph):
    order = []
    processNext = []
    inEdges = {}
    for i in graph:
        inEdges[i] = 0
        for j in graph:
            for i in graph[j]:
                inEdges[i] += 1
        if inEdges[i] == 0:
            processNext.append(i)

    while processNext:
        curr = processNext.pop(0)
        for i in graph[curr]:
            inEdges[i] -= 1
            if inEdges[i] == 0:
                processNext.append(i)
        order.append(curr)

    return order

if __name__ == '__main__':
    tsort = toposort(graph)

    print(tsort)