#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define MAXN 2501
#define INF 3e10
typedef long long ll;
struct node{
int cur;
int cur_w;
ll cur_wl;
bool operator < (const node& a) const{
return a.cur_wl < cur_wl;
}
};
int Won[MAXN];
vector<pair<int,int> > adj[MAXN];
ll dist[MAXN][MAXN];
int N,M;
ll dijkstra(){
priority_queue<node> pq;
pq.push({1,Won[1],0});
dist[1][Won[1]] = 0;
while (!pq.empty()){
int cur = pq.top().cur;
ll cur_wl = pq.top().cur_wl;
int cur_w = pq.top().cur_w;
pq.pop();
if (cur == N) return cur_wl;
for (int i = 0 ;i < adj[cur].size(); i++){
int next = adj[cur][i].first;
int next_l = adj[cur][i].second;
ll next_wl = cur_wl + (ll)cur_w*next_l;
if (dist[next][min(cur_w,Won[next])] > next_wl){
dist[next][min(cur_w,Won[next])] = next_wl;
pq.push({next,min(cur_w,Won[next]),next_wl});
}
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N >> M;
for (int i = 1; i <=N ; i++){
cin >> Won[i];
}
while (M--){
int u,v,l;
cin >> u >> v >> l;
adj[u].push_back({v,l});
adj[v].push_back({u,l});
}
for (int i = 1; i <=N; i++){
for (int j = 1; j<MAXN; j++){
dist[i][j] = INF;
}
}
cout << dijkstra() <<"\n";
return 0;
}