""" """ import sys from sys import stdin import heapq N,M = map(int,stdin.readline().split()) lis = [ [] for i in range(N) ] for i in range(M): A,B,C = map(int,stdin.readline().split()) A -= 1 B -= 1 lis[A].append( (B,C) ) lis[B].append( (A,C) ) T = list(map(int,stdin.readline().split())) dp = [[float("inf")] * 1002 for i in range(N)] dp[0][T[0]] = T[0] q = [] heapq.heappush( q , (T[0] , 0 , T[0]) ) while q: ncost , nv , np = heapq.heappop(q) if dp[nv][np] != ncost: continue if nv == N-1: print (ncost) sys.exit() for nexv,ecost in lis[nv]: nexcost = ncost + ecost // np + T[nexv] if dp[nexv][min(1001,np+T[nexv])] > nexcost: dp[nexv][min(1001,np+T[nexv])] = nexcost heapq.heappush(q , (nexcost,nexv,np+T[nexv]) )