#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long subtree[200001];
long long Tree_num(long long v) {
  if (subtree[v] != v) {
    subtree[v] = Tree_num(subtree[v]);
  }
  return subtree[v];
}
long long Kruscal(vector<pair<long long, pair<long long, long long>>>& graph) {
  for (long long i = 0; i < n; ++i) {
    subtree[i] = i;
  }
  sort(graph.begin(), graph.end());
  long long result = 0;
  for (long long i = 0; i < n + m; ++i) {
    long long u = Tree_num(graph[i].second.first);
    long long v = Tree_num(graph[i].second.second);
    if (u != v) {
      subtree[u] = v;
      result += graph[i].first;
      ;
    }
  }
  return result;
}
int main() {
  cin >> n >> m;
  vector<long long> a(n);
  long long min_index;
  long long minimum = 10000000000000;
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] < minimum) {
      minimum = a[i];
      min_index = i;
    }
  }
  vector<pair<long long, pair<long long, long long>>> graph(n + m);
  long long index = 0;
  for (long long i = 0; i < n; ++i) {
    graph[i].first = minimum + a[i];
    graph[i].second.first = i;
    graph[i].second.second = min_index;
  }
  long long u, v, wes;
  for (long long i = n; i < n + m; ++i) {
    cin >> u >> v >> wes;
    graph[i].first = wes;
    graph[i].second.first = --u;
    graph[i].second.second = --v;
  }
  cout << Kruscal(graph);
  return 0;
}
