#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
const int N = 2e5 + 100;
const ll INF = 3e12;
ll res;
struct node {
  ll a, mn;
  int sz = 1;
  node *root = this;
  node *get_root() { return root == this ? this : root = root->get_root(); }
  bool join(node *o) {
    node *a = get_root(), *b = o->get_root();
    if (a == b) {
      return false;
    }
    if (a->sz < b->sz) {
      swap(a, b);
    }
    b->root = a;
    a->sz += b->sz;
    b->sz = 0;
    a->mn = min(a->mn, b->mn);
    return true;
  }
  ll cost(node *o) {
    node *a = get_root(), *b = o->get_root();
    if (a == b) {
      return 0;
    }
    return a->mn + b->mn;
  }
} nodes[N], *np[N], *mn;
struct offer {
  node *x, *y;
  ll w;
  inline bool operator<(const offer &o) const { return w < o.w; }
} offers[N];
int n, m, x, y;
int main() {
  ios_base::sync_with_stdio(false), cout.tie(nullptr), cin.tie(nullptr);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    auto &nd = nodes[i];
    cin >> nd.a;
    nd.mn = nd.a;
    np[i] = &nd;
  }
  for (int i = 0; i < m; i++) {
    auto &o = offers[i];
    cin >> x >> y >> o.w;
    o.x = nodes + x;
    o.y = nodes + y;
  }
  sort(offers, offers + m);
  sort(np + 1, np + 1 + n, [](node *a, node *b) { return a->a < b->a; });
  int oi = 0;
  mn = np[1];
  ll tmp1, tmp2;
  for (int i = 2; i <= n;) {
    tmp1 = mn->cost(np[i]);
    tmp2 = oi >= m ? INF : offers[oi].w;
    if (tmp1 < tmp2) {
      if (mn->join(np[i])) {
        res += tmp1;
      }
      i++;
    } else {
      if (offers[oi].x->join(offers[oi].y)) {
        res += tmp2;
      }
      oi++;
    }
  }
  cout << res;
}
