#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2 * 1e5 + 55;
bool vis[maxn];
const long long inf = 1e18;
long long n;
long long con[maxn], org[maxn], owner[maxn];
vector<pair<long long, long long>> adj[maxn];
bool required[maxn];
long long res = 0;
vector<pair<long long, long long>> vevo;
long long a[maxn];
void Prim() {
  res = 0;
  for (long long i = 0; i < n; i++) {
    owner[i] = -1;
    org[i] = inf;
    required[i] = false;
  }
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      pq;
  long long r = vevo[0].second;
  pq.push(make_pair(0, r));
  org[r] = 0;
  long long cnt = 0;
  for (long long j = 0; j < n; ++j) {
    if (j == r) continue;
    long long dis = min(con[j], a[j] + a[r]);
    org[j] = dis;
    owner[j] = r;
    pq.push({dis, j});
  }
  while (!pq.empty()) {
    pair<long long, long long> p = pq.top();
    pq.pop();
    long long u = p.second;
    if (!required[u]) {
      required[u] = true;
      res += p.first;
      cnt++;
      if (cnt == n) return;
      for (pair<long long, long long> p : adj[u]) {
        long long v = p.first, w = p.second;
        if (!required[v])
          if (org[v] > w) {
            org[v] = w, pq.push(make_pair(w, v));
            owner[v] = u;
          }
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  memset(vis, false, sizeof vis);
  long long m;
  cin >> n >> m;
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
    vevo.push_back({a[i], i});
  }
  sort(vevo.begin(), vevo.end());
  for (long long i = 0; i < n; ++i) con[i] = inf;
  long long r = vevo[0].second;
  for (long long i = 0; i < m; ++i) {
    long long u, v, w;
    cin >> u >> v >> w;
    --u, --v;
    adj[u].push_back({v, w});
    adj[v].push_back({u, w});
  }
  con[r] = 0;
  for (auto p : adj[r]) {
    long long j = p.first, w = p.second;
    con[j] = min(con[j], w);
  }
  Prim();
  cout << res;
}
