#include <bits/stdc++.h>
using namespace std;
class UnionFind {
  vector<int> par, sz;

 public:
  UnionFind() {}
  UnionFind(int n) {
    par = sz = vector<int>(n);
    for (int i = 0; i < n; i++) {
      par[i] = i;
      sz[i] = 1;
    }
  }
  int find(int x) {
    if (par[x] == x) return x;
    return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (sz[x] > sz[y]) {
      par[y] = x;
      sz[x] += sz[y];
    } else {
      par[x] = y;
      sz[y] += sz[x];
    }
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return sz[find(x)]; }
};
struct st {
  int a, b;
  long long c;
};
pair<long long, int> a[300000];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<st> v;
  for (int i = 0; i < (n); i++) {
    scanf("%lld", &a[i].first);
    a[i].second = i;
  }
  sort(a, a + n);
  for (int i = 1; i < n; i++) {
    v.push_back({a[0].second, a[i].second, a[0].first + a[i].first});
  }
  for (int i = 0; i < (m); i++) {
    int x, y;
    long long w;
    scanf("%d%d%lld", &x, &y, &w);
    x--;
    y--;
    v.push_back({x, y, w});
  }
  sort(v.begin(), v.end(), [](st a, st b) { return a.c < b.c; });
  UnionFind uf(n);
  long long sum = 0;
  for (st& p : v) {
    if (uf.same(p.a, p.b)) continue;
    sum += p.c;
    uf.unite(p.a, p.b);
  }
  cout << sum << endl;
}
