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