#include <bits/stdc++.h>
using namespace std;
const long long int N = 2e5 + 1;
long long int par[N];
long long int sz[N];
void init(long long int n) {
  for (long long int i = 1; i <= n; i++) {
    par[i] = i;
    sz[i] = 1;
  }
}
long long int root(long long int x) {
  while (x != par[x]) {
    par[x] = par[par[x]];
    x = par[x];
  }
  return x;
}
bool unite(long long int x, long long int y) {
  long long int rx = root(x);
  long long int ry = root(y);
  if (rx == ry) return 0;
  if (sz[rx] <= sz[ry]) {
    par[rx] = ry;
    sz[ry] += sz[rx];
  } else {
    par[ry] = rx;
    sz[rx] += sz[ry];
  }
  return 1;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int n, m;
  cin >> n >> m;
  vector<pair<long long int, long long int>> a(n);
  for (long long int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i + 1;
  }
  sort(a.begin(), a.end());
  vector<pair<long long int, pair<long long int, long long int>>> edges;
  for (long long int i = 1; i < n; i++)
    edges.push_back({a[0].first + a[i].first, {a[0].second, a[i].second}});
  for (long long int i = 1; i <= m; i++) {
    long long int x, y, w;
    cin >> x >> y >> w;
    edges.push_back({w, {x, y}});
  }
  sort(edges.begin(), edges.end());
  long long int ans = 0;
  init(n);
  for (auto it : edges) {
    long long int u = it.second.first;
    long long int v = it.second.second;
    long long int w = it.first;
    if (unite(u, v)) ans += w;
  }
  cout << ans;
}
