#include <bits/stdc++.h>
using namespace std;
struct Disjoint_set {
  int n;
  vector<int> parent, Rank;
  Disjoint_set() {}
  Disjoint_set(int _n) {
    n = _n;
    parent = vector<int>(n + 2);
    Rank = vector<int>(n + 2);
    for (int i = 0; i <= n; i++) {
      parent[i] = i;
    }
  }
  int findparent(int x) {
    if (parent[x] == x)
      return x;
    else
      return parent[x] = findparent(parent[x]);
  }
  int mergenodes(int x, int y) {
    int a = findparent(x);
    int b = findparent(y);
    if (a == b)
      return 0;
    else {
      if (Rank[a] > Rank[b])
        parent[b] = a;
      else if (Rank[b] > Rank[a])
        parent[a] = b;
      else {
        parent[a] = b;
        Rank[b]++;
      }
      return 1;
    }
  }
};
struct kruskal {
  int n;
  Disjoint_set D, Dd;
  kruskal(int n) : n(n), D(n) {}
  vector<pair<long long, pair<int, int> > > edges;
  void addedge(int x, int y, long long w) { edges.push_back({w, {x, y}}); }
  long long Minst() {
    long long mst = 0;
    sort(edges.begin(), edges.end());
    for (int i = 0; i < edges.size(); i++) {
      if (D.mergenodes(edges[i].second.first, edges[i].second.second))
        mst += edges[i].first;
    }
    return mst;
  }
};
long long val[200005];
int main() {
  int n, m, best_node;
  long long best_val = 1e15;
  cin >> n >> m;
  n++;
  kruskal K(n);
  for (int i = 1; i < n; i++) {
    cin >> val[i];
    if (val[i] < best_val) {
      best_val = val[i];
      best_node = i;
    }
  }
  for (int i = 1; i < n; i++) {
    if (i == best_node) continue;
    K.addedge(i, best_node, val[i] + best_val);
  }
  while (m--) {
    int u, v;
    long long w;
    cin >> u >> v >> w;
    K.addedge(u, v, w);
  }
  cout << K.Minst() << endl;
  return 0;
}
