#include <bits/stdc++.h>
using namespace std;
const int N = 400000 + 77;
int n, m, P[N], Qv[N], Qu[N], Par[N], Mn = 1;
long long T[N], Qw[N], A;
bool CMP(int x, int y) { return Qw[x] < Qw[y]; }
int Find(int x) { return Par[x] == 0 ? x : (Par[x] = Find(Par[x])); }
inline void Merge(int v, int u, long long w) {
  v = Find(v);
  u = Find(u);
  if (v == u) return;
  Par[v] = u;
  A += w;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> T[i];
    if (T[Mn] > T[i]) Mn = i;
  }
  for (int i = 1; i <= m; ++i) cin >> Qv[i] >> Qu[i] >> Qw[i], P[i] = i;
  for (int i = 1; i <= n; ++i) {
    P[m + i] = m + i;
    Qv[m + i] = Mn;
    Qu[m + i] = i;
    Qw[m + i] = T[Mn] + T[i];
  }
  sort(P + 1, P + m + n + 1, CMP);
  for (int i = 1; i <= m + n; ++i) {
    int id = P[i];
    Merge(Qv[id], Qu[id], Qw[id]);
  }
  cout << A;
  return 0;
}
