def WarshallFloyd(N, Cost): for k in range(N): for i in range(N): for j in range(N): if Cost[i][k] + Cost[k][j] < Cost[i][j]: Cost[i][j] = Cost[i][k] + Cost[k][j] return Cost INF = 1<<100 N,M = map(int,input().split()) Cost = [[INF] * N for _ in range(N)] for i in range(N): Cost[i][i] = 0 for _ in range(M): s,t,d = map(int,input().split()) s -= 1 t -= 1 Cost[s][t] = d Cost = WarshallFloyd(N, Cost) for i in range(N): ans = 0 for j in range(N): if Cost[i][j] <= INF // 2: ans += Cost[i][j] print(ans)