N,M=map(int, input().split()) D=[[] for i in range(N)] for i in range(M): a,b,c=map(int,input().split()) a-=1;b-=1 D[a].append((b,c)) D[b].append((a,c)) from collections import deque d=deque() #,1は行きがけ、,0は帰りがけ d.append((0,1,0)) V=[0]*N ans=0;f=0 while d: now,x,c=d.pop() if x==1: f+=c ans=max(ans,2*f) V[now]=1 d.append((now,0,c)) for nex,c in D[now]: if V[nex]==0: d.append((nex,1,c)) else: V[now]=0 f-=c print(ans)