N,M=map(int,input().split()) point=[[0 for _ in range(N)] for _ in range(N)] for _ in range(M): t1,t2,p=map(int,input().split()) point[t2][t1]=p MAX=1<0:p+=point[to][i] dp[s][to]=max(dp[s][to],dp[bs][frm]+p) ans=max(dp[-1]) print(ans)