#include <bits/stdc++.h>
using namespace std;
long long k[200001], s[200001];
int find(int x) {
  while (x != k[x]) x = k[x];
  return k[x];
}
bool same(int a, int b) { return find(a) == find(b); }
void unite(int a, int b) {
  a = find(a);
  b = find(b);
  if (s[a] < s[b]) swap(a, b);
  s[a] += s[b];
  k[b] = a;
}
vector<tuple<long long, int, int> > graph;
long long res = 0;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < 200001; i++) k[i] = i, s[i] = 1;
  vector<long long> power;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    power.push_back(x);
  }
  long long min_node = min_element(power.begin(), power.end()) - power.begin();
  for (int i = 0; i < n; i++)
    if (i != min_node)
      graph.push_back(
          tuple<long long, int, int>(power[min_node] + power[i], min_node, i));
  for (int i = 0; i < m; i++) {
    int a, b;
    long long w;
    cin >> a >> b >> w;
    graph.push_back(make_tuple(w, a - 1, b - 1));
  }
  sort(graph.begin(), graph.end());
  for (auto it : graph)
    if (!same(get<1>(it), get<2>(it))) {
      unite(get<1>(it), get<2>(it));
      res += get<0>(it);
    }
  cout << res << endl;
  return 0;
}
