from heapq import heapify, heappop, heappush N,M = map(int,input().split()); INF = float("inf") G = [[] for _ in range(N)] for _ in range(M): a,b,c = map(int,input().split()) a-=1;b-=1 G[a].append((c,b)) G[b].append((c,a)) T = list(map(int,input().split())) MAX = pow(10,3) + 10 #dp[i][j]: i番目の街にいて、おにぎりを計j分食べた時の最小値 dp = [[INF]*MAX for _ in range(N)] #dp[0][T[0]] = 0 #S:start, V: node, E: Edge, G: Graph V = len(G) PQ = [] s = 0 heappush(PQ,(0,s,T[0])) #時間:c,町:v,おにぎり:p dp[0][T[0]] = T[0] while PQ: c,v,p = heappop(PQ) #おにぎりを食べて到着 #print(c,v,p,dp[v][p]) #ここで食べる #print(c,v,p,dp[v][p]) #if dp[v][p] < c: # continue #dp[v][p] = c for dis,u in G[v]: np = min(p + T[u], 1001) if dp[u][np] <= dis//p + dp[v][p] + T[u]: continue dp[u][np] = dis//p + dp[v][p] + T[u] #print(u,dp[u][np]) heappush(PQ,(dp[u][np], u, np)) #print(dp) ans = min(dp[N-1]) print(ans)