#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
int p[MAXN];
int get(int a) {
  if (p[a] == a) {
    return a;
  }
  return p[a] = get(p[a]);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  set<pair<long long, int>> cost;
  int n, m;
  cin >> n >> m;
  vector<long long> a(n + 1);
  set<pair<long long, pair<int, int>>> qs;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    cost.insert(make_pair(a[i], i));
  }
  for (int i = 1; i <= n; ++i) p[i] = i;
  long long ans = 0;
  for (int i = 0; i < m; ++i) {
    int u, v;
    long long len;
    cin >> u >> v >> len;
    qs.insert(make_pair(len, make_pair(u, v)));
  }
  while (cost.size() != 1) {
    auto Fir = *cost.begin();
    cost.erase(Fir);
    auto Sec = *cost.begin();
    cost.erase(Sec);
    int u = Fir.second, v = Sec.second;
    int uu = get(u), vv = get(v);
    if (uu == vv) {
      cost.insert(Fir);
      continue;
    }
    while (qs.size()) {
      auto it = *qs.begin();
      if (get(it.second.first) == get(it.second.second))
        qs.erase(it);
      else
        break;
    }
    if (qs.size() == 0) {
      ans += a[u] + a[v];
      if (min(a[u], a[v]) == a[u])
        cost.insert(make_pair(a[u], u));
      else
        cost.insert(make_pair(a[v], v));
      p[uu] = vv;
    } else {
      long long C = (*qs.begin()).first;
      if (C < a[u] + a[v]) {
        cost.insert(Fir);
        cost.insert(Sec);
        ans += C;
        auto it = *qs.begin();
        u = it.second.first, v = it.second.second;
        uu = get(u), vv = get(v);
        p[uu] = vv;
        if (min(a[u], a[v]) == a[u]) {
          cost.erase(make_pair(a[v], v));
          cost.insert(make_pair(a[u], u));
        } else {
          cost.erase(make_pair(a[u], u));
          cost.insert(make_pair(a[v], v));
        }
        qs.erase(it);
      } else {
        ans += a[u] + a[v];
        if (min(a[u], a[v]) == a[u])
          cost.insert(make_pair(a[u], u));
        else
          cost.insert(make_pair(a[v], v));
        p[uu] = vv;
      }
    }
  }
  cout << ans;
  return 0;
}
