#include <bits/stdc++.h>
int leader(int x, std::vector<int>& prev) {
  return (x == prev[x] ? x : (prev[x] = leader(prev[x], prev)));
}
bool merge(int x, int y, std::vector<int>& prev) {
  x = leader(x, prev);
  y = leader(y, prev);
  if (x == y) return 0;
  prev[x] = y;
  return 1;
}
int main() {
  int n, m, x, y;
  std::cin >> n >> m;
  long long ai, w, res = 0ll;
  long long a[n];
  for (int i = 0; i < n; ++i) {
    std::cin >> ai;
    a[i] = ai;
  }
  std::vector<std::pair<long long, std::pair<int, int>>> edges;
  for (int i = 0; i < m; ++i) {
    std::cin >> x >> y >> w;
    edges.push_back(std::make_pair(w, std::make_pair(x - 1, y - 1)));
  }
  std::vector<int> prev;
  for (int i = 0; i < n; ++i) prev.push_back(i);
  int z = std::min_element(a, a + n) - a;
  for (int i = 0; i < n; ++i)
    if (i != z)
      edges.push_back(std::make_pair(a[i] + a[z], std::make_pair(i, z)));
  std::sort(edges.begin(), edges.end());
  for (const auto& e : edges)
    if (merge(e.second.first, e.second.second, prev)) res += e.first;
  std::cout << res;
  return 0;
}
