from heapq import heapify, heappop, heappush from collections import defaultdict n, m = map(int, input().split()) edge = defaultdict(list) max_c = 0 for _ in range(m): a, b, c = map(int, input().split()) a -= 1 b -= 1 max_c = max(max_c, c) edge[a].append((b, c)) edge[b].append((a, c)) T = list(map(int, input().split())) H = [(T[0], T[0], 0)] heapify(H) while H: t, et, cp = heappop(H) if cp == n - 1: print(t) break for np, tt in edge[cp]: nt = t + tt // et heappush(H, (nt + T[np], min(et + T[np], max_c + 1), np))