#include <bits/stdc++.h>
using namespace std;
const int MAX = 200005;
const int MOD = 998244353;
int n, arr[MAX];
struct node {
  int u, v;
  long long cost;
  bool operator<(const node &n) const { return cost < n.cost; }
};
vector<struct node> e;
vector<pair<long long, int> > v;
int par[MAX];
int findpar(int r) {
  if (par[r] == r) return r;
  par[r] = findpar(par[r]);
  return par[r];
}
long long mst() {
  sort(e.begin(), e.end());
  int c = 0;
  long long sum = 0;
  for (int i = 0; i < e.size(); i++) {
    int u = findpar(e[i].u);
    int v = findpar(e[i].v);
    if (u != v) {
      par[u] = v;
      sum += e[i].cost;
      c++;
      if (c == n - 1) break;
    }
  }
  if (c != n - 1) return -1;
  return sum;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int m;
  cin >> n >> m;
  for (int i = 0; i <= n; i++) par[i] = i;
  for (int i = 1; i <= n; i++) {
    long long w;
    cin >> w;
    v.push_back(make_pair(w, i));
  }
  if (n == 1) return cout << 0 << "\n", 0;
  sort(v.begin(), v.end());
  pair<long long, int> p = v[0];
  for (int i = 1; i < v.size(); i++) {
    struct node a;
    a.u = p.second;
    a.v = v[i].second;
    a.cost = v[i].first + p.first;
    e.push_back(a);
  }
  for (int i = 0; i < m; i++) {
    int u, v;
    long long cost;
    cin >> u >> v >> cost;
    struct node a;
    a.u = u;
    a.v = v;
    a.cost = cost;
    e.push_back(a);
  }
  long long ans = mst();
  cout << ans << "\n";
}
