#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int maxn = 2e5 + 100;
long long ans, n, m;
vector<pair<long long, long long> > v[maxn];
bool mark[maxn];
set<pair<long long, long long> > s, ragham;
long long mins;
long long a[maxn];
void add(long long i, long long j) {
  ans += j;
  mins = min(mins, a[i]);
  ragham.erase(pair<long long, long long>(a[i], i));
  mark[i] = 1;
  for (long long y = 0; y < v[i].size(); y++) {
    pair<long long, long long> x = v[i][y];
    if (!mark[x.first]) s.insert(pair<long long, long long>(x.second, x.first));
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  mins = 1LL * 1e13;
  for (long long y = 1; y <= n; y++) {
    cin >> a[y];
    ragham.insert(pair<long long, long long>(a[y], y));
  }
  for (long long y = 1; y <= m; y++) {
    long long i, j, k;
    cin >> i >> j >> k;
    v[i].push_back(pair<long long, long long>(j, k));
    v[j].push_back(pair<long long, long long>(i, k));
  }
  add(1, 0);
  mins = a[1];
  while (ragham.size()) {
    if (s.size() == 0) {
      pair<long long, long long> i = *ragham.begin();
      add(i.second, i.first + mins);
      continue;
    }
    pair<long long, long long> j = *s.begin();
    pair<long long, long long> i = *ragham.begin();
    if (mark[j.second]) {
      s.erase(j);
      continue;
    }
    if (i.first + mins < j.first) {
      add(i.second, i.first + mins);
    } else {
      add(j.second, j.first);
      s.erase(j);
    }
  }
  cout << ans;
}
