#include <bits/stdc++.h>
using namespace std;
void init() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
};
struct node1 {
  long long v;
  int flag;
} a[1000000];
struct node {
  int x, y;
  long long v;
} b[1000000];
bool cmp(node a, node b) { return a.v < b.v; }
int c[1000000];
int find(int x) { return x != c[x] ? find(c[x]) : x; }
int main() {
  init();
  int n, m;
  cin >> n >> m;
  a[n].v = 1000000000000;
  for (int i = 0; i < n; i++) {
    cin >> a[i].v;
    a[i].flag = i + 1;
    if (a[n].v >= a[i].v) {
      a[n].v = a[i].v;
      a[n].flag = a[i].flag;
    }
  }
  for (int i = 0; i < m; i++) cin >> b[i].x >> b[i].y >> b[i].v;
  for (int i = 0; i < n; i++) {
    if (a[n].flag != a[i].flag) {
      b[m].x = a[n].flag;
      b[m].y = a[i].flag;
      b[m++].v = a[n].v + a[i].v;
    }
  }
  sort(b, b + m, cmp);
  long long ans = 0;
  for (int i = 0; i <= n; i++) c[i] = i;
  int cnt = 0;
  for (int i = 0; i < m; i++) {
    if (cnt == n - 1) break;
    int x = find(b[i].x);
    int y = find(b[i].y);
    c[b[i].x] = x;
    c[b[i].y] = y;
    if (x != y) {
      c[x] = y;
      ans += b[i].v;
      cnt++;
    }
  }
  cout << ans << endl;
  return 0;
}
