#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool umax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
pair<long long, pair<int, int> > edge[200009 * 2];
long long arr[200009];
int ata[200009];
int tap(int x) {
  if (ata[x] == x) return x;
  return ata[x] = tap(ata[x]);
}
bool merge(int x, int y) {
  if ((x = tap(x)) == (y = tap(y))) return 0;
  return ata[y] = x;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  long long mn = (1e14);
  int who;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", arr + i);
    if (umin(mn, arr[i])) who = i;
    ata[i] = i;
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    long long w;
    scanf("%d%d%lld", &u, &v, &w);
    edge[i] = make_pair(w, make_pair(u, v));
  }
  for (int i = 1; i <= n; i++)
    if (who != i) edge[++m] = make_pair(arr[i] + mn, make_pair(i, who));
  sort(edge + 1, edge + m + 1);
  long long ans = 0;
  for (int i = 1; i <= m; i++)
    if (merge(edge[i].second.first, edge[i].second.second))
      ans += edge[i].first;
  printf("%lld\n", ans);
  return 0;
}
