from collections import deque n,m=map(int,input().split()) ans=[[10**10]*(11**5+200) for _ in range(n)] num=[[] for _ in range(n)] for i in range(m): a,b,c=map(int,input().split()) num[a-1].append([b-1,c]) num[b-1].append([a-1,c]) t=list(map(int,input().split())) ans[0][t[0]]=t[0] queue=deque() queue.append([0,t[0]]) seen=[False]*n seen[0]=True while len(queue)!=0: num1=queue.popleft() h1=num1[0] h2=num1[1] num2=num[h1] seen[h1]=True num3=ans[h1][h2] for i in range(len(num2)): j=num2[i][0] if h2+t[j]<11**5+200: cnt=num3+num2[i][1]//h2+t[j] if ans[j][h2+t[j]]>cnt: ans[j][h2+t[j]]=cnt queue.append([j,h2+t[j]]) print(min(ans[-1]))