#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using mint = modint998244353;

struct edge {
  int to, cost;
};

int main() {
  int N, M; cin >> N >> M;
  vector<vector<edge>> g(N);
  for (int i = 0; i < M; i++) {
    int a, b, c; cin >> a >> b >> c;
    a--, b--;
    g[a].push_back({b, c});
    g[b].push_back({a, c});
  }
  vector<int> t(N);
  for (int i = 0; i < N; i++) cin >> t[i];
  vector<vector<ll>> dist(N, vector<ll>(1010, 1e18));
  dist[0][0] = 0;
  priority_queue<array<ll, 3>, vector<array<ll, 3>>, greater<array<ll, 3>>> pq;
  pq.push({0, 0, 0});
  while (!pq.empty()) {
    auto [c, v, p] = pq.top(); pq.pop();
    if (dist[v][p] < c) continue;
    c += t[v]; p = min(p + t[v], 1001LL);
    for (auto e: g[v]) {
      if (dist[e.to][p] > c + e.cost / p) {
        dist[e.to][p] = c + e.cost / p;
        pq.push({c + e.cost /p, e.to, p});
      }
    }
  }
  ll ans = 1e18;
  for (int i = 0; i <= 1001; i++) ans = min(ans, dist[N - 1][i]);
  cout << ans << endl;
  return 0;
}