import heapq N,M = map(int,input().split()) G = {i:[] for i in range(1,N+1)} cmax = 0 for _ in range(M): a,b,c = map(int,input().split()) cmax = max(cmax,c) G[a].append((b,c)) G[b].append((a,c)) T = [0]+list(map(int,input().split())) F = {(i,j):[] for i in range(1,N+1) for j in range(1,cmax+2)} for i in range(1,N+1): for j in range(1,cmax+2): for k,c in G[i]: nj = j+T[k] if nj>=cmax+1: nj = cmax+1 F[(i,j)].append((k,nj,c)) INFTY = 10**9 dist = [[INFTY for _ in range(cmax+2)] for _ in range(N+1)] hist = [[0 for _ in range(cmax+2)] for _ in range(N+1)] dist[1][T[1]] = T[1] heap = [(T[1],1,T[1])] while heap: d,x,j = heapq.heappop(heap) if dist[x][j]d+c//j+T[y] and hist[y][nj]==0: dist[y][nj] = d+c//j+T[y] heapq.heappush(heap,(dist[y][nj],y,nj)) ans = INFTY for j in range(1,cmax+2): ans = min(ans,dist[N][j]) print(ans)