from collections import defaultdict import sys sys.setrecursionlimit(10 ** 6) def dfs(i, vst, d=0): mx = d for ki, kd in to[i]: if ki in vst: continue vst.add(ki) tmp = dfs(ki, vst, d + kd) vst.remove(ki) if tmp > mx: mx = tmp return mx n, m = map(int, input().split()) to = defaultdict(list) for _ in range(m): a, b, c = map(int, input().split()) a -= 1 b -= 1 to[a].append([b, c]) to[b].append([a, c]) print(max(dfs(i,set([i])) for i in range(n)))