#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
int cnt = 0;
int fa[200005];
long long coin[200005];
long long sum = 0;
long long mini = 999999999999999;
long long mininum = 0;
int n, m;
long long read() {
  long long num = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9') {
    num = num * 10 + ch - '0';
    ch = getchar();
  }
  return num;
}
struct Tree {
  long long u;
  long long v;
  long long cost;
  long long next;
  bool operator<(Tree t) const { return cost < t.cost; }
} tr[1000005];
long long Find(long long x) {
  if (x == fa[x])
    return x;
  else
    return fa[x] = Find(fa[x]);
}
void MST() {
  for (int i = 1; i <= cnt; i++) {
    long long u = Find(tr[i].u);
    long long v = Find(tr[i].v);
    if (u == v) continue;
    long long w = tr[i].cost;
    fa[u] = v;
    sum += w;
  }
}
int main() {
  n = read();
  m = read();
  int i;
  for (i = 1; i <= n; i++) {
    fa[i] = i;
    coin[i] = read();
    if (mini > coin[i]) {
      mini = coin[i];
      mininum = i;
    }
  }
  for (i = 1; i <= m; i++) {
    long long x, y, w;
    x = read();
    y = read();
    w = read();
    tr[i] = {x, y, w};
  }
  cnt = m;
  for (i = 1; i <= n; i++) {
    if (i == mininum) continue;
    tr[++cnt] = {mininum, i, mini + coin[i]};
  }
  sort(tr + 1, tr + cnt + 1);
  MST();
  cout << sum << endl;
  return 0;
}
