#include <bits/stdc++.h>
using namespace std;
struct data {
  long long fr, sc, tr;
};
bool trmp(const data& A, const data& B) { return A.tr < B.tr; }
vector<data> vdt;
vector<pair<long long, long long> > vct;
long long par[200003];
long long fin(long long r) {
  if (par[r] == r)
    return r;
  else {
    par[r] = fin(par[r]);
    return par[r];
  }
}
long long kruskal(long long n, long long m) {
  long long p = 0, q, z = 0, a, b, c, d, e, f, g, i, j, ans = 0, cnt = 0, u, v;
  a = vct[0].first;
  b = vct[0].second;
  for (i = 1; i <= n - 1; i++) {
    c = vct[i].first;
    d = vct[i].second;
    e = a + c;
    f = min(b, d);
    g = max(b, d);
    if (z < m) {
      c = vdt[z].fr;
      d = vdt[z].sc;
      j = vdt[z].tr;
      if (j <= e) {
        if (f != c || g != d) {
          i--;
        }
        e = j;
        f = c;
        g = d;
        z++;
      }
    }
    u = fin(f);
    v = fin(g);
    if (u != v) {
      ans = ans + e;
      par[v] = u;
      cnt++;
      if (cnt == n - 1) break;
    }
  }
  return ans;
}
int main() {
  long long n, m, i, j, x, y, w, a, b, c;
  data dt;
  scanf("%lld %lld", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%lld", &a);
    vct.push_back(make_pair(a, i));
    par[i] = i;
  }
  for (i = 1; i <= m; i++) {
    scanf("%lld %lld %lld", &x, &y, &w);
    a = min(x, y);
    b = max(x, y);
    c = min((vct[a - 1].first + vct[b - 1].first), w);
    dt.fr = a;
    dt.sc = b;
    dt.tr = c;
    vdt.push_back(dt);
  }
  if (n == 1)
    printf("0\n");
  else {
    sort(vct.begin(), vct.end());
    sort(vdt.begin(), vdt.end(), trmp);
    printf("%lld\n", kruskal(n, m));
  }
  return 0;
}
