#include <bits/stdc++.h>
using namespace std;
long long n, m, x, pos, z, y, xmin;
long long a[200005];
vector<pair<long long, pair<long long, long long> > > v;
long long id[200005];
long long find(long long src) {
  if (id[src] == src) return src;
  return id[src] = find(id[src]);
}
void uni(long long x, long long y) {
  long long xx = find(x);
  long long yy = find(y);
  if (xx != yy) {
    id[xx] = yy;
  }
}
bool issame(long long x, long long y) { return find(x) == find(y); }
int main() {
  cin >> n >> m;
  xmin = 1e18;
  for (int i = 0; i < n; i++) {
    id[i] = i;
    scanf("%I64d", &a[i]);
    xmin = min(xmin, a[i]);
    if (a[i] == xmin) pos = i;
  }
  for (int i = 0; i < n; i++) {
    if (i == pos) continue;
    v.push_back(make_pair(a[i] + xmin, make_pair(pos, i)));
  }
  for (int i = 0; i < m; i++) {
    scanf("%I64d %I64d %I64d", &x, &y, &z);
    x--;
    y--;
    v.push_back(make_pair(z, make_pair(x, y)));
  }
  sort(v.begin(), v.end());
  long long ans = 0;
  for (int i = 0; i < v.size(); i++) {
    x = v[i].second.first;
    y = v[i].second.second;
    if (issame(x, y) == 0) {
      ans += v[i].first;
      uni(x, y);
    }
  }
  cout << ans;
  return 0;
}
