from collections import defaultdict import sys sys.setrecursionlimit(10**6) def dfs(i, oi=-1, d=0): if len(to[i]) == 1: if to[i][0][0] == oi: return d mx = 0 for ki, kd in to[i]: if ki == oi: continue tmp = dfs(ki, i, d + kd) 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) for i in range(n)))