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 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)] 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,c=LI() u,v=u-1,v-1 to[u].append((v,c)) to[v].append((u,c)) tt=LI() mx=100000 dist=[[inf]*mx for _ in range(n)] dist[0][0]=0 hp=[(0,0,0)] while hp: d,u,p=heappop(hp) if u==n-1: print(d) break if d>dist[u][p]:continue p+=tt[u] if p>=mx:continue for v,c in to[u]: nd=d+tt[u]+c//p if dist[v][p]<=nd:continue dist[v][p]=nd heappush(hp,(nd,v,p))