#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
struct weigh {
  long long x, y, z;
} wt[N];
bool cmp(weigh a, weigh b) { return a.z < b.z; }
long long a[N], b[N];
int rnk(int x) {
  while (x != a[x]) a[x] = a[a[x]], x = a[x];
  return x;
}
int main() {
  int n, m;
  cin >> n >> m;
  multiset<pair<long long, long long> > s;
  long long x, y, z;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &x);
    s.insert({x, i});
    a[i] = i;
    b[i] = x;
  }
  for (int i = 1; i <= m; i++) {
    scanf("%lld %lld %lld", &x, &y, &z);
    wt[i] = {x, y, z};
  }
  sort(wt + 1, wt + m + 1, cmp);
  x = 1;
  long long ans = 0;
  for (int i = 1; i < n; i++) {
    while (x <= m && rnk(wt[x].x) == rnk(wt[x].y)) x++;
    if (x <= m) {
      auto it = s.begin();
      auto it1 = *it;
      it++;
      auto it2 = *it;
      y = it1.first + it2.first;
      if (y <= wt[x].z) {
        ans += y;
        b[rnk(it2.second)] = min(it1.first, it2.first);
        a[rnk(it1.second)] = rnk(it2.second);
        s.erase(s.find(it1));
        s.erase(s.find(it2));
        s.insert({b[rnk(it2.second)], rnk(it2.second)});
      } else {
        ans += wt[x].z;
        it1 = *s.find({b[rnk(wt[x].x)], rnk(wt[x].x)});
        it2 = *s.find({b[rnk(wt[x].y)], rnk(wt[x].y)});
        b[rnk(wt[x].y)] = min(b[rnk(wt[x].x)], b[rnk(wt[x].y)]);
        a[rnk(wt[x].x)] = rnk(wt[x].y);
        s.erase(it1);
        s.erase(it2);
        s.insert({b[rnk(wt[x].y)], rnk(wt[x].y)});
        x++;
      }
    } else {
      auto it = s.begin();
      auto it1 = *it;
      it++;
      auto it2 = *it;
      y = it1.first + it2.first;
      ans += y;
      b[rnk(it2.second)] = min(it1.first, it2.first);
      a[rnk(it1.second)] = rnk(it2.second);
      s.erase(s.find(it1));
      s.erase(s.find(it2));
      s.insert({b[rnk(it2.second)], rnk(it2.second)});
    }
  }
  cout << ans;
  return 0;
}
