#include <bits/stdc++.h>
using namespace std;
long long int a[200001];
pair<long long int, int> b[200001];
int par[200001];
int root(int v) { return par[v] < 0 ? v : root(par[v]); }
void merge(int x, int y) {
  if ((x = root(x)) == (y = root(y))) return;
  if (par[y] < par[x]) swap(x, y);
  par[x] += par[y];
  par[y] = x;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    b[i].first = a[i];
    b[i].second = i;
    par[i] = -1;
  }
  sort(b + 1, b + n + 1);
  set<pair<long long int, pair<int, int> > > s;
  for (int i = 0; i < m; i++) {
    int x, y;
    long long int we;
    cin >> x >> y >> we;
    pair<long long int, pair<int, int> > ed;
    ed.first = we;
    ed.second.first = x;
    ed.second.second = y;
    s.insert(ed);
  }
  long long int maidx = 1;
  long long int components = n;
  long long int ans = 0;
  while (components > 1) {
    if (!s.empty()) {
      pair<long long int, pair<int, int> > ed = *s.begin();
      int u = ed.second.first, v = ed.second.second;
      if (root(u) == root(v)) {
        s.erase(s.begin());
      } else {
        long long int mw = ed.first;
        while (root(b[1].second) == root(b[maidx].second)) {
          maidx++;
        }
        if (mw <= b[1].first + b[maidx].first) {
          ans += mw;
          merge(u, v);
          s.erase(s.begin());
          components--;
        } else {
          ans += b[1].first + b[maidx].first;
          merge(b[1].second, b[maidx].second);
          components--;
        }
      }
    } else {
      while (root(b[1].second) == root(b[maidx].second)) {
        maidx++;
      }
      ans += b[1].first + b[maidx].first;
      merge(b[1].second, b[maidx].second);
      components--;
    }
  }
  cout << ans << endl;
  return 0;
}
