import heapq import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) inf = 1 << 62 class D: def __init__(self, dist, now, P) -> None: self.dist = dist self.now = now self.P = P def __lt__(self, rhs): return self.dist < rhs.dist def main(): N, M = map(int, input().split()) G = [[] for _ in range(N + N)] for _ in range(M): a, b, c = map(int, input().split()) a -= 1 b -= 1 G[a+N].append((b, c)) G[b+N].append((a, c)) T = list(map(int, input().split())) for i, t in enumerate(T): G[i].append((i+N, t)) dist = [[inf] * 1001 for _ in range(N + N)] dist[0][0] = 0 pq = [D(0, 0, 0)] # time, now, eat while pq: X = heapq.heappop(pq) ds = X.dist s = X.now P = X.P if dist[s][P] < ds: continue for t, dt in G[s]: if t == s + N and P + dt <= 1000: if dist[t][P + dt] > ds + dt: dist[t][P + dt] = ds + dt heapq.heappush(pq, D(ds + dt, t, P + dt)) else: if dist[t][P] > ds + dt // P: dist[t][P] = ds + dt // P heapq.heappush(pq, D(ds + dt // P, t, P)) ans = inf for i in range(1001): ans = min(ans, dist[N-1][i]) print(ans) main()