#include <bits/stdc++.h>
using namespace std;
int const inf = (int)2e9;
int const mod = (int)1e9 + 7;
vector<int> link, sz;
vector<long long> x;
int find(int a) {
  while (link[a] != a) a = link[a];
  return a;
}
bool same(int a, int b) { return (find(a) == find(b)); }
void unite(int a, int b) {
  if (same(a, b)) return;
  a = find(a), b = find(b);
  if (sz[a] < sz[b]) swap(a, b);
  sz[a] += sz[b];
  link[b] = a;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  x.resize(n + 1);
  link.resize(n + 1);
  sz.resize(n + 1, 1);
  int ind = -1;
  for (int i = 1; i <= n; ++i) {
    cin >> x[i];
    link[i] = i;
    if (ind == -1 || x[ind] > x[i]) ind = i;
  }
  vector<tuple<long long, int, int>> edges;
  for (int i = 0; i < m; ++i) {
    int v, u;
    long long w;
    cin >> v >> u >> w;
    edges.emplace_back(w, v, u);
  }
  for (int i = 1; i <= n; ++i) {
    if (ind != i) edges.emplace_back(x[ind] + x[i], ind, i);
  }
  sort((edges).begin(), (edges).end());
  long long ans = 0;
  for (auto e : edges) {
    int v, u;
    long long w;
    tie(w, v, u) = e;
    v = find(v);
    u = find(u);
    if (v == u) continue;
    ans += w;
    unite(v, u);
  }
  cout << ans;
}
