#include <bits/stdc++.h>
using namespace std;
const int mx = 2e5;
int n, m;
long long w[mx + 3];
int pre[mx + 3];
long long cost = 0;
int sum;
struct Node {
  int st;
  int to;
  long long v;
} sx[mx * 2 + 3];
bool cmp(const Node &a, const Node &b) { return a.v < b.v; }
int unfind(int x) {
  int r = x;
  while (r != pre[r]) {
    r = pre[r];
  }
  int t;
  while (pre[x] != r) {
    t = pre[x];
    pre[x] = r;
    x = t;
  }
  return r;
}
int unjoin(int x, int y) {
  int fx = unfind(x), fy = unfind(y);
  if (fx != fy) {
    pre[fx] = fy;
    sum--;
    return 1;
  }
  return 0;
}
void kursual(int cnt) {
  sum = n;
  for (int i = 1; i <= cnt; ++i) {
    if (unjoin(sx[i].st, sx[i].to)) {
      cost += sx[i].v;
    }
    if (!sum) return;
  }
  return;
}
int main() {
  long long minn = 0x3f3f3f3f3f3f3f3f;
  int xb;
  int cnt = 0;
  int a, b;
  long long c;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    pre[i] = i;
    scanf("%I64d", &w[i]);
    if (minn > w[i]) {
      minn = w[i];
      xb = i;
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (i != xb) {
      sx[++cnt].st = xb;
      sx[cnt].to = i;
      sx[cnt].v = w[i] + w[xb];
    }
  }
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d%I64d", &a, &b, &c);
    if (w[a] + w[b] > c) {
      sx[++cnt].st = a;
      sx[cnt].to = b;
      sx[cnt].v = c;
    }
  }
  sort(sx + 1, sx + cnt + 1, cmp);
  kursual(cnt);
  printf("%I64d\n", cost);
}
