#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long double eps = 1e-7;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 200010;
struct DSU {
  int par[MAXN];
  DSU() {
    for (int i = 1; i < MAXN; i++) par[i] = i;
  }
  int get(int x) {
    if (par[x] == x) return x;
    return par[x] = get(par[x]);
  }
  long long join(int a, int b) {
    if (get(a) == get(b)) return 0;
    par[get(a)] = get(b);
    return 1;
  }
} dsu;
long long n, m, k, u, v, x, y, t, a, b, ans;
long long A[MAXN];
pair<long long, pair<int, int> > E[MAXN * 2];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> A[i];
  for (int i = 0; i < m; i++)
    cin >> E[i].second.first >> E[i].second.second >> E[i].first;
  int mn = min_element(A + 1, A + n + 1) - A;
  for (int i = 1; i <= n; i++) E[m + i - 1] = {A[i] + A[mn], {i, mn}};
  sort(E, E + m + n);
  for (int i = 0; i < m + n; i++) {
    long long w = E[i].first, u = E[i].second.first, v = E[i].second.second;
    ans += w * dsu.join(u, v);
  }
  cout << ans << endl;
  return 0;
}
