import sys sys.setrecursionlimit(10**6) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.buffer.readline()) def FI(): return float(sys.stdin.buffer.readline()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LI1(): return list(map(int1, sys.stdin.buffer.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def BI(): return sys.stdin.buffer.readline().rstrip() def SI(): return sys.stdin.buffer.readline().rstrip().decode() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] dij = [(0, 1), (1, 0), (1, 1), (1, -1)] inf = 10**16 # md = 998244353 md = 10**9+7 from heapq import * n,m=LI() to=[[] for _ in range(n)] for _ in range(m): u,v,d=LI() u,v=u-1,v-1 to[u].append((v,d)) to[v].append((u,d)) ww=[0]*n ww[0]=inf ee=[inf]*n ee[0]=0 hp=[(-inf,0)] while hp: w,u=heappop(hp) w=-w if w=nw:continue ww[v]=nw heappush(hp,(-nw,v)) hp=[(0,0)] while hp: e,u=heappop(hp) if e>ee[u]:continue if u==n-1:break for v,lim in to[u]: if lim