n,m=map(int,input().split()) e=[[] for i in range(n)] for i in range(m): a,b,c=map(int,input().split()) a-=1 b-=1 e[a]+=[(b,c)] e[b]+=[(a,c)] o=list(map(int,input().split())) X=10**10 v=[[(X,X)]*1002 for i in range(n)] v[0][1]=(0,0) q=[(v[0][1],0,1)] from heapq import heappush,heappop while len(q)>0: sc,sp,so=heappop(q) if sc>v[sp][so]: continue if sp==n-1: break st1,st2=sc[0],-sc[1] tt2=st2+o[sp] to=so+1 for tp,tc in e[sp]: tt1=st1+o[sp]+tc//tt2 if to<=1001 and v[tp][to]>(tt1,-tt2): v[tp][to]=(tt1,-tt2) heappush(q,(v[tp][to],tp,to)) print(min(v[n-1][i][0] for i in range(1002)))