#include <bits/stdc++.h>
int top(int x, std::vector<int>& prev) {
  if (x == prev[x]) return x;
  prev[x] = top(prev[x], prev);
  return prev[x];
}
bool combine(int x, int y, std::vector<int>& prev) {
  x = top(x, prev);
  y = top(y, prev);
  return (x == y) ? 0 : (prev[x] = y) == y;
}
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::set<std::pair<long long, std::pair<int, int>>> edges;
  for (int i = 0; i < m; ++i) {
    std::cin >> x >> y >> w;
    edges.insert(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 min_index = std::min_element(a, a + n) - a;
  for (int i = 0; i < n; ++i)
    if (i != min_index)
      edges.insert(
          std::make_pair(a[i] + a[min_index], std::make_pair(i, min_index)));
  for (const auto& e : edges)
    if (combine(e.second.first, e.second.second, prev)) res += e.first;
  std::cout << res;
  return 0;
}
