from heapq import * n, m = map(int, input().split()) edges = [[] for _ in range(n)] for _ in range(m): a, b, c = map(int, input().split()) a -= 1 b -= 1 edges[a].append((b, c)) edges[b].append((a, c)) T = list(map(int, input().split())) inf = 1 << 60 dist = [[inf] * 1001 for _ in range(n)] dist[0][0] = 0 hq = [(0, 0, 0)] while hq: d, pos, p = heappop(hq) if dist[pos][p] < d: continue p += T[pos] p = min(p, 1000) d += T[pos] for npos, c in edges[pos]: tmp = min(d + c // p, 1000) if dist[npos][p] > tmp: dist[npos][p] = tmp heappush(hq, (tmp, npos, p)) print(min(dist[-1]))