#include <bits/stdc++.h>
using namespace std;
vector<int> v[200005];
vector<int> par(200005, -1);
vector<int> ran(200005, 1);
int fi(int c) {
  while (1) {
    if (par[c] == -1)
      return c;
    else
      c = par[c];
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  long long int a[n];
  long long int val = 10000000000000000;
  int in;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] < val) {
      val = a[i];
      in = i;
    }
  }
  vector<pair<long long int, pair<int, int> > > v;
  for (int i = 0; i < n; i++) {
    if (i != in) {
      v.push_back({a[i] + val, {i, in}});
    }
  }
  long long int sum = 0;
  while (m--) {
    int x, y;
    cin >> x >> y;
    long long int z;
    cin >> z;
    x--, y--;
    v.push_back({z, {x, y}});
  }
  sort(v.begin(), v.end());
  int s = v.size();
  for (int i = 0; i < s; i++) {
    int t1 = v[i].second.first;
    int t2 = v[i].second.second;
    int t3 = fi(t1);
    int t4 = fi(t2);
    if (t3 != t4) {
      if (ran[t3] > ran[t4]) {
        par[t4] = t3;
        ran[t3] += ran[t4];
      } else {
        par[t3] = t4;
        ran[t4] += ran[t3];
      }
      sum += v[i].first;
    }
  }
  cout << sum;
}
