#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e5 + 7;
long long parent[MAXN], rank1[MAXN];
vector<pair<long long, pair<long long, long long>>> edges;
void makest(long long v) {
  parent[v] = v;
  rank1[v] = 0;
}
long long find(long long v) {
  if (v == parent[v]) return v;
  return parent[v] = find(parent[v]);
}
void merge(long long a, long long b) {
  a = find(a);
  b = find(b);
  if (a != b) {
    if (rank1[a] < rank1[b]) swap(a, b);
    parent[b] = a;
    if (rank1[a] == rank1[b]) rank1[a]++;
  }
}
signed main() {
  long long n, m, mini = 1e14, node, ans = 0;
  cin >> n >> m;
  long long a[n + 1];
  for (long long i = 1; i <= n; ++i) {
    cin >> a[i];
    if (mini > a[i]) {
      mini = a[i];
      node = i;
    }
  }
  for (long long i = 1; i <= n; ++i) {
    makest(i);
  }
  long long x, y, z;
  for (long long i = 1; i <= m; ++i) {
    cin >> x >> y >> z;
    edges.push_back({z, {x, y}});
  }
  for (long long i = 1; i <= n; ++i) {
    if (i != node) {
      edges.push_back({mini + a[i], {i, node}});
    }
  }
  sort(edges.begin(), edges.end());
  for (auto t : edges) {
    x = t.second.first;
    y = t.second.second;
    z = t.first;
    if (find(x) != find(y)) {
      ans += z;
      merge(x, y);
    }
  }
  cout << ans << "\n";
}
