#include using namespace std; using ll=long long; using ull=unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) struct Edge{ int to; int d; }; using dijkstra_queue = priority_queue>,vector>>,greater>>>; int N,M; vector> E; int D[100][1001]; int C[100]; int main(){ cin>>N>>M; E.resize(N); rep(i,M){ int u,v,c; cin>>u>>v>>c; u--; v--; E[u].push_back({v,c}); E[v].push_back({u,c}); } rep(i,N) cin>>C[i]; rep(i,N) rep(d,1001) D[i][d]=-1; dijkstra_queue Q; D[0][0]=0; Q.push({0,{0,0}}); while(Q.size()){ int p=Q.top().second.first; int c=Q.top().second.second; int t=Q.top().first; Q.pop(); if(D[p][c]!=t) continue; c += C[p]; t += C[p]; c = min(c,1000); for(Edge e:E[p]){ int nxt = t + e.d / c; if(D[e.to][c] != -1 && D[e.to][c] <= nxt) continue; D[e.to][c] = nxt; Q.push({nxt,{e.to,c}}); } } int ans=1001001001; rep(i,1001){ if(D[N-1][i]!=-1) ans=min(ans,D[N-1][i]); } cout<