from collections import deque class Node(): def __init__(self, id): self.id = id self.state = 0 self.children = [] ### n,m = list(map(int, input().split(' '))) scores = [] for i in range(n): r = [0] * n scores.append(r) children = {} for i in range(m): p,c,s = list(map(int, input().split(' '))) if p not in children: children[p] = [c] else: children[p].append(c) scores[p][c] = s ### nodes = [] for p in range(n): nodes.append(Node(p)) for parent in nodes: for c in sorted(children[parent.id]): parent.children.append(nodes[c]) ### def dfs(parent, parents, sum, sums): parent.status = 1 for child in parent.children: if child.status == 0: parents.append(parent) for p in parents: sum += scores[p.id][child.id] dfs(child, parents, sum, sums) else: sums.append(sum) def reset(): for node in nodes: node.status = 0 for child in node.children: child.status = 0 ### sums = [] for parent in nodes: for child in parent.children: reset() parent.status = 1 dfs(child, [parent], scores[parent.id][child.id], sums) print(sorted(sums)[len(sums)-1])