#include <bits/stdc++.h>
using namespace std;
const int _maxn = 200011, _maxm = 200011;
struct node {
  int at;
  long long va;
  friend bool operator<(node le, node ri) { return le.va > ri.va; }
} no;
bool visi[_maxn];
int n, m, u, v, firs[_maxn], neig[_maxm << 1], arri[_maxm << 1];
long long a[_maxn], w, valu[_maxm << 1], nomi, rans;
priority_queue<node> nopu, edpu;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &a[i]);
    no.at = i;
    no.va = a[i];
    nopu.push(no);
  }
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d%lld", &u, &v, &w);
    neig[i << 1] = firs[u];
    firs[u] = i << 1;
    arri[i << 1] = v;
    valu[i << 1] = w;
    neig[i << 1 | 1] = firs[v];
    firs[v] = i << 1 | 1;
    arri[i << 1 | 1] = u;
    valu[i << 1 | 1] = w;
  }
  visi[1] = 1;
  nomi = a[1];
  for (int i = firs[1]; i; i = neig[i]) {
    no.at = i >> 1;
    no.va = valu[i];
    edpu.push(no);
  }
  for (int i = 1; i < n; ++i) {
    while ((!nopu.empty()) && visi[nopu.top().at]) nopu.pop();
    while ((!edpu.empty()) && visi[arri[edpu.top().at << 1]] +
                                      visi[arri[edpu.top().at << 1 | 1]] !=
                                  1)
      edpu.pop();
    if (edpu.empty() || nopu.top().va + nomi < edpu.top().va) {
      rans += nopu.top().va + nomi;
      visi[nopu.top().at] = 1;
      nomi = min(nomi, nopu.top().va);
      for (int i = firs[nopu.top().at]; i; i = neig[i]) {
        no.at = i >> 1;
        no.va = valu[i];
        edpu.push(no);
      }
    } else {
      rans += edpu.top().va;
      if (visi[arri[edpu.top().at << 1]]) {
        visi[arri[edpu.top().at << 1 | 1]] = 1;
        nomi = min(nomi, a[arri[edpu.top().at << 1 | 1]]);
        for (int i = firs[arri[edpu.top().at << 1 | 1]]; i; i = neig[i]) {
          no.at = i >> 1;
          no.va = valu[i];
          edpu.push(no);
        }
      } else {
        visi[arri[edpu.top().at << 1]] = 1;
        nomi = min(nomi, a[arri[edpu.top().at << 1]]);
        for (int i = firs[arri[edpu.top().at << 1]]; i; i = neig[i]) {
          no.at = i >> 1;
          no.va = valu[i];
          edpu.push(no);
        }
      }
    }
  }
  printf("%lld", rans);
  return 0;
}
