#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<long long> arr;
vector<int> parents;
long long minCost = LLONG_MAX;
long long costOutput;
struct edge {
  int u, v;
  long long cost;
  edge(){};
  edge(int u_, int v_, long long cost_) {
    u = u_;
    v = v_;
    cost = cost_;
  }
};
struct less_than_key {
  inline bool operator()(const edge& edge1, const edge& edge2) {
    return (edge1.cost < edge2.cost);
  }
};
vector<edge> edges;
void init() {
  costOutput = 0;
  for (int i = 0; i <= n; i++) {
    parents.push_back(i);
  }
}
int find(int u) {
  int i = u;
  while (parents[i] != i) {
    int parentOfI = parents[i];
    parents[i] = parents[parentOfI];
    i = parentOfI;
  }
  return i;
}
void connect(int u, int v, long long cost) {
  int parentU = find(u);
  int parentV = find(v);
  if (parentU == parentV) return;
  if (arr[parentU] > arr[parentV]) {
    swap(parentU, parentV);
  }
  if (cost + minCost + min(arr[parentU], arr[parentV]) <
      2 * minCost + arr[parentU] + arr[parentV]) {
    costOutput += cost;
    parents[parentV] = parentU;
  }
}
int main() {
  cin >> n >> m;
  arr.push_back(-1);
  for (int i = 0; i < n; i++) {
    long long num;
    cin >> num;
    arr.push_back(num);
    minCost = min(minCost, num);
  }
  init();
  for (int i = 0; i < m; i++) {
    int a, b;
    long long cost;
    cin >> a >> b >> cost;
    edges.push_back(edge(a, b, cost));
  }
  sort(edges.begin(), edges.end(), less_than_key());
  for (int i = 0; i < m; i++) {
    connect(edges[i].u, edges[i].v, edges[i].cost);
  }
  int minParent = 1;
  set<int> allParents;
  for (int i = 1; i <= n; i++) {
    int root = find(parents[i]);
    allParents.insert(root);
    if (arr[minParent] > arr[root]) {
      minParent = root;
    }
  }
  allParents.erase(minParent);
  set<int>::iterator it = allParents.begin();
  while (it != allParents.end()) {
    costOutput += arr[minParent] + arr[*it];
    it++;
  }
  cout << costOutput << endl;
  return 0;
}
