#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1};
const int M = 100005 * 3;
pair<long long, long long> p[M];
vector<pair<long long, pair<long long, long long> > > d;
long long a[M], par[M];
long long Union_Find(int v) {
  if (par[v] == v) return v;
  return par[v] = Union_Find(par[v]);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  long long u, v, c;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    p[i] = {a[i], i};
    par[i] = i;
  }
  sort(p + 1, p + 1 + n);
  for (int i = 2; i <= n; i++) {
    d.push_back({p[1].first + p[i].first, {p[1].second, p[i].second}});
  }
  for (int i = 1; i <= m; i++) {
    cin >> u >> v >> c;
    d.push_back({c, {u, v}});
  }
  sort(d.begin(), d.end());
  long long up, vp;
  long long sum = 0;
  for (auto x : d) {
    c = x.first;
    u = x.second.first;
    v = x.second.second;
    up = Union_Find(u);
    vp = Union_Find(v);
    if (up != vp) {
      par[up] = vp;
      sum += c;
    }
  }
  cout << sum << endl;
  return 0;
}
