#include <bits/stdc++.h>
using namespace std;
const long long inff = 0x3f3f3f3f3f3f3f3f;
long long n, a[200008], mi = 1, x, y, z, m, ans;
struct as {
  long long u, v, d;
} b[500008];
int fa[200008];
bool cmp(as a, as b) { return a.d < b.d; }
int fid(int x) {
  int a = x, b;
  while (fa[a] != a) a = fa[a];
  while (x != a) b = fa[x], fa[x] = a, x = b;
  return a;
}
int main() {
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i(1); i <= (n); ++i) {
    scanf("%lld", &a[i]), fa[i] = i;
    if (a[i] < a[mi]) mi = i;
  }
  for (int i(1); i <= (m); ++i)
    scanf("%lld", &b[i].u), scanf("%lld", &b[i].v), scanf("%lld", &b[i].d);
  for (int i(1); i <= (n); ++i)
    b[++m].u = i, b[m].v = mi, b[m].d = a[mi] + a[i];
  sort(b + 1, b + m + 1, cmp);
  for (int i(1); i <= (m); ++i) {
    x = fid(b[i].u), y = fid(b[i].v);
    if (x != y) fa[x] = y, ans += b[i].d;
  }
  cout << ans << endl;
  return 0;
}
