#include <bits/stdc++.h>
using namespace std;
class dsu {
 public:
  vector<long long> v, si;
  dsu(long long n) {
    v.resize(n + 2);
    si.resize(n + 2);
    for (long long i = 0; i <= n + 1; i++) {
      v[i] = i;
      si[i] = 1;
    }
  }
  inline long long parent(long long x) {
    while (x != v[x]) {
      v[x] = v[v[x]];
      x = v[x];
    }
    return x;
  }
  inline bool unite(long long x, long long y) {
    x = parent(x);
    y = parent(y);
    if (x != y) {
      if (si[x] > si[y]) {
        v[y] = x;
        si[x] += si[y];
        si[y] = 0;
      } else {
        v[x] = y;
        si[y] += si[x];
        si[x] = 0;
      }
      return 1;
    }
    return 0;
  }
};
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  vector<long long> v(n);
  vector<vector<long long>> sp;
  for (long long &i : v) cin >> i;
  for (long long i = 0; i < k; ++i) {
    long long a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    sp.push_back({c, a, b});
  }
  long long root = min_element(v.begin(), v.end()) - v.begin();
  for (long long i = 0; i < n; ++i) {
    sp.push_back({v[i] + v[root], i, root});
  }
  sort(sp.begin(), sp.end());
  dsu tree(n + 2);
  long long cost = 0;
  for (vector<long long> i : sp) {
    if (tree.unite(i[1], i[2])) cost += i[0];
  }
  cout << cost;
  return 0;
}
