#include <bits/stdc++.h>   using namespace std;   struct UnionFind {     vector<int> par;     vector<int> rank;     vector<int> sz;     UnionFind(int n = 0) {       if (n > 0) initialize(n);     }     void initialize(int n) {       par.resize(n);       rank.resize(n);       sz.resize(n);       for (int i = 0; i < n; i++) {         par[i] = i;         rank[i] = 0;         sz[i] = 1;       }     }     int find(int x) {       if (par[x] == x) {         return x;       } else {         return par[x] = find(par[x]);       }     }     void unite(int x, int y) {       x = find(x);       y = find(y);       if (x == y) return;       if (rank[x] < rank[y]) {         par[x] = y;         sz[y] += sz[x];       } else {         par[y] = x;         sz[x] += sz[y];         if (rank[x] == rank[y]) rank[x]++;       }     }     bool same(int x, int y) { return find(x) == find(y); }   };   int main() {     int N, M;     cin >> N >> M;     static pair<int64_t, int> A[200000];     for (int i = 0; i < N; i++) {       int64_t a;       scanf( %lld , &a);       A[i] = {a, i};     }     vector<vector<int64_t>> edges;     for (int i = 0; i < M; i++) {       int64_t x, y, w;       scanf( %lld %lld %lld , &x, &y, &w);       edges.push_back({w, x - 1, y - 1});     }     sort(A, A + N);     int64_t first = A[0].second;     for (int i = 1; i < N; i++) {       int64_t j = A[i].second;       int64_t cost = A[0].first + A[i].first;       edges.push_back({cost, first, j});     }     sort(edges.begin(), edges.end());     int64_t ans = 0;     UnionFind uf(N);     for (auto& v : edges) {       int i = v[1], j = v[2];       if (!uf.same(i, j)) {         ans += v[0];         uf.unite(i, j);       }     }     cout << ans << endl;     return 0;   }   