#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 7;
const long long INF = 1e9 + 10;
const long long INF64 = 1e18;
const long long MOD = 1e9 + 7;
const long long MODLL = 1e10 + 13;
const long long base = 311;
queue<int> que;
long long n, m, a[N], u, v, c, res, p[N], sl;
struct Node {
  long long x, y, w;
  Node(){};
  Node(long long xx, long long yy, long long ww) {
    x = xx;
    y = yy;
    w = ww;
  }
};
bool cmp(Node A1, Node B1) { return A1.w < B1.w; }
int getroot(int x) {
  if (p[x] == 0) return x;
  p[x] = getroot(p[x]);
  return p[x];
}
vector<Node> Edge;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  long long mmin = INF64;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    mmin = min(a[i], mmin);
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == mmin) {
      for (int j = 1; j <= n; j++)
        if (i != j) Edge.push_back(Node(i, j, a[i] + a[j]));
      break;
    }
  }
  for (int i = 1; i <= m; i++) {
    cin >> u >> v >> c;
    Edge.push_back(Node(u, v, c));
  }
  sort(Edge.begin(), Edge.end(), cmp);
  sl = 1;
  for (int i = 0; i < Edge.size(); i++) {
    int x = getroot(Edge[i].x);
    int y = getroot(Edge[i].y);
    if (x != y) {
      res += Edge[i].w;
      p[x] = y;
      sl++;
      if (sl == n) break;
    }
  }
  cout << res;
  return 0;
}
