#include <bits/stdc++.h>
using namespace std;
const long long inf = 1100000000000000000;
const long double PI =
    3.141592653589793238462643383279502884197169399375105820974944;
long long n, m;
long long a[300100];
vector<pair<long long, long long>> g[300100];
long long par[300100];
long long fin(long long x) {
  if (x == par[x]) return x;
  return par[x] = fin(par[x]);
}
void uni(long long x, long long y) {
  long long px = fin(x);
  long long py = fin(y);
  if (px != py) par[px] = py;
}
void solve() {
  cin >> n >> m;
  for (long long i = 0; i < n; i++) par[i] = i;
  for (long long i = 0; i < n; i++) cin >> a[i];
  multiset<pair<long long, pair<long long, long long>>> st;
  for (long long i = 0; i < m; i++) {
    long long x, y, w;
    cin >> x >> y >> w;
    --x, --y;
    w = min(w, a[x] + a[y]);
    st.insert({w, {x, y}});
  }
  multiset<pair<long long, long long>> s;
  for (long long i = 0; i < n; i++) s.insert({a[i], i});
  for (long long i = 0; i < n; i++) {
    s.erase({a[i], i});
    auto it = *(s.begin());
    long long mn = it.first + a[i], id = it.second;
    st.insert({mn, {i, id}});
    s.insert({a[i], i});
  }
  long long ans = 0;
  while (!st.empty()) {
    auto it = st.begin();
    auto cur = *it;
    st.erase(it);
    if (fin(cur.second.first) != fin(cur.second.second)) {
      ans += cur.first;
      uni(cur.second.first, cur.second.second);
    }
  }
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  long long T = 1;
  while (T--) {
    solve();
    cout << '\n';
  }
  return 0;
}
