from sys import stdin N, M = map(int, stdin.readline().split()) edges = [[] for i in range(N+1)] for i in range(M): a, b, c = map(int, stdin.readline().split()) edges[a].append((b, c)) edges[b].append((a, c)) import sys sys.setrecursionlimit(10**7) def dfs(current, distance, mx): for nxt, nxt_d in edges[current]: if visited[nxt] == 0: visited[nxt] = 1 mx_temp = max(mx, nxt_d) distance_list[nxt].add((distance+nxt_d, mx_temp, distance+nxt_d - mx_temp)) dfs(nxt, distance+nxt_d, mx_temp) visited[nxt] = 0 distance_list = [set() for i in range(N+1)] visited = [0]*(N+1) visited[1] = 1 dfs(1, 0, 0) for i in range(1, N+1): if i == 1: print(0) else: shortest = 10**10 skip_shortest = 10**10 for total, dummy, net in distance_list[i]: shortest = min(shortest, total) skip_shortest = min(skip_shortest, net) ans = shortest + skip_shortest print(ans)