from heapq import heappush, heappop n,m = map(int,input().split()) e = [[] for i in range(n)] for i in range(m): a,b,c = map(int,input().split()) a -= 1 b -= 1 e[a].append((b,c)) e[b].append((a,c)) T = list(map(int,input().split())) inf = 10**10 dis = [[inf]*(1002) for i in range(n)] h = [(0,0,0)] while h: d,p,now = heappop(h) p *= -1 if dis[now][p] <= d: continue dis[now][p] = d np = min(p+T[now],1001) for nex,c in e[now]: if dis[nex][np] > dis[now][p]+T[now]+c//np: heappush(h, (dis[now][p]+T[now]+c//np,-np,nex)) print(min(dis[-1]))