#include <bits/stdc++.h>
using namespace std;
long long int p[1000000], h[1000000];
map<pair<long long int, long long int>, long long int> sp;
vector<pair<long long int, long long int> > ai;
vector<long long int> graph[1000000];
vector<pair<pair<long long int, long long int>, long long int> > kr;
long long int parent(long long int x) {
  return p[x] = ((p[x] == x) ? x : parent(p[x]));
}
void unite(long long int x, long long int y) {
  long long int px = parent(x), py = parent(y);
  if (h[px] < h[py])
    p[px] = py, h[py] = max(h[py], h[px] + 1);
  else
    p[py] = px, h[px] = max(h[px], h[py] + 1);
}
signed main() {
  long long int x, y, n, w, m, a, val[1000000];
  cin >> n >> m;
  for (long long int i = 1; i <= n; i++)
    cin >> a, val[i] = a, ai.push_back(make_pair(a, i)), p[i] = i, h[i] = 0;
  for (long long int i = 0; i < m; i++) {
    cin >> x >> y >> w;
    graph[x].push_back(y);
    graph[y].push_back(x);
    sp[make_pair(x, y)] = min(w, val[x] + val[y]);
    sp[make_pair(y, x)] = min(w, val[x] + val[y]);
    kr.push_back(make_pair(make_pair(sp[make_pair(x, y)], x), y));
  }
  sort(ai.begin(), ai.end());
  for (long long int i = 1; i < n; i++) {
    x = ai[0].second, y = ai[i].second;
    a = ai[0].first + ai[i].first;
    if (!sp[make_pair(x, y)])
      graph[x].push_back(y), graph[y].push_back(x),
          kr.push_back(make_pair(make_pair(a, x), y)),
          sp[make_pair(x, y)] = a, sp[make_pair(x, y)] = a;
  }
  sort(kr.begin(), kr.end());
  long long int cnt = 0, ans = 0;
  for (long long int i = 0; i < kr.size() && cnt <= n - 1; i++) {
    w = kr[i].first.first, x = kr[i].first.second, y = kr[i].second;
    if (parent(x) != parent(y)) ans += w, unite(x, y), cnt++;
  }
  cout << ans;
  return 0;
}
