def main(): try: import sys sys.setrecursionlimit(10**7) except: pass from math import sqrt,sin,cos,tan,ceil,radians,floor,gcd,exp,log,log10,log2,factorial,fsum from heapq import heapify, heappop, heappush from bisect import bisect_left, bisect_right from copy import deepcopy import copy import random from collections import deque,Counter,defaultdict from itertools import permutations,combinations from decimal import Decimal,ROUND_HALF_UP #tmp = Decimal(mid).quantize(Decimal('0'), rounding=ROUND_HALF_UP) from functools import lru_cache, reduce #@lru_cache(maxsize=None) from operator import add,sub,mul,xor,and_,or_,itemgetter INF = 10**18 mod1 = 10**9+7 mod2 = 998244353 #DecimalならPython ''' ''' N,M = map(int, input().split()) G = [[] for _ in range(N+1)] for _ in range(M): a,b,c = map(int, input().split()) G[a].append((b,c)) G[b].append((a,c)) Q = [] heappush(Q,(0,1,0)) dis = [[INF]*2 for _ in range(N+1)] dis[0][1] = 0 while len(Q) > 0: cnt,pos,f = heappop(Q) if dis[pos][f] != INF: continue dis[pos][f] = cnt if f == 1 and dis[pos][1] >= dis[pos][0]: continue for nx,d in G[pos]: if dis[nx][f] == INF and cnt