#include <bits/stdc++.h>
using namespace std;
using VS = vector<string>;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
using VL = vector<LL>;
using VVL = vector<VL>;
const int INF = 1e9;
const LL LINF = 1e16;
const LL MOD = 1000000007;
const double PI = acos(-1.0);
template <typename T>
struct VoronoiMST {
  int n;
  using E = pair<int, T>;
  using P = pair<T, int>;
  vector<vector<E> > G;
  VoronoiMST(vector<T> &x) {
    n = x.size();
    G.assign(n << 1, vector<E>());
    for (int i = 0; i < n; i++) G[i].emplace_back(n + i, x[i]);
  }
  VoronoiMST(int sn) : n(sn) { G.assign(n << 1, vector<E>()); }
  void add_edge(int u, int v, T c) {
    G[u + n].emplace_back(v + n, c);
    G[v + n].emplace_back(u + n, c);
  }
  vector<vector<E> > build() {
    priority_queue<P, vector<P>, greater<P> > pq;
    const T INF = numeric_limits<T>::max();
    vector<T> dist(n << 1, INF);
    vector<int> from(n << 1, -1);
    for (int i = 0; i < n; i++) {
      dist[i] = 0;
      from[i] = i;
      pq.emplace(dist[i], i);
    }
    while (!pq.empty()) {
      T d;
      int v;
      tie(d, v) = pq.top();
      pq.pop();
      if (dist[v] < d) continue;
      for (E e : G[v]) {
        int u = e.first;
        T c = e.second;
        if (dist[u] <= dist[v] + c) continue;
        dist[u] = dist[v] + c;
        from[u] = from[v];
        pq.emplace(dist[u], u);
      }
    }
    vector<vector<E> > H(n);
    for (int v = 0; v < (n << 1); v++) {
      for (E e : G[v]) {
        int u = e.first;
        T c = e.second;
        if (from[v] == from[u]) continue;
        int x = from[v], y = from[u];
        T z = dist[v] + dist[u] + c;
        H[x].emplace_back(y, z);
        H[y].emplace_back(x, z);
      }
    }
    return H;
  }
};
template <typename T>
struct Kruskal {
  struct edge {
    int from, to;
    T cost;
    int used;
    edge() {}
    edge(int from, int to, T cost) : from(from), to(to), cost(cost), used(0) {}
    bool operator<(const edge &e) const { return cost < e.cost; }
  };
  int n;
  vector<int> p, r;
  vector<edge> edges;
  Kruskal() {}
  Kruskal(int n) : n(n) {}
  void init(int n) {
    r.assign(n, 1);
    p.resize(n);
    iota(p.begin(), p.end(), 0);
  }
  int find(int x) { return (x == p[x] ? x : p[x] = find(p[x])); }
  bool same(int x, int y) { return find(x) == find(y); }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (r[x] < r[y]) swap(x, y);
    r[x] += r[y];
    p[y] = x;
  }
  void add_edge(int u, int v, T c) { edges.emplace_back(u, v, c); }
  T build() {
    sort(edges.begin(), edges.end());
    init(n);
    T res = 0;
    for (auto &e : edges) {
      if (!same(e.from, e.to)) {
        res += e.cost;
        unite(e.from, e.to);
        e.used = 1;
      }
    }
    return res;
  }
};
void solve_KEYENCE2019_E() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int N, D;
  cin >> N >> D;
  vector<long long> a(N);
  for (int i = 0; i < N; i++) cin >> a[i];
  VoronoiMST<long long> vo(a);
  for (int i = 1; i < N; i++) {
    vo.add_edge(i - 1, i, D);
  }
  auto G = vo.build();
  Kruskal<long long> ks(N);
  for (int v = 0; v < N; v++) {
    for (auto e : G[v]) {
      int u = e.first;
      long long c = e.second;
      if (v < u) ks.add_edge(v, u, c);
    }
  }
  cout << ks.build() << endl;
}
void solve_Codefestival2017_final_J() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  LL N;
  cin >> N;
  vector<long long> a(N);
  for (int i = 0; i < N; i++) cin >> a[i];
  VoronoiMST<long long> vo(a);
  for (int i = 1; i < N; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    x--, y--;
    vo.add_edge(x, y, z);
  }
  auto G = vo.build();
  Kruskal<long long> ks(N);
  for (int v = 0; v < N; v++) {
    for (auto e : G[v]) {
      int u = e.first;
      long long c = e.second;
      if (v < u) ks.add_edge(v, u, c);
    }
  }
  cout << ks.build() << endl;
}
void solve_CF_529_F() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  LL N;
  cin >> N;
  LL M;
  cin >> M;
  vector<long long> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  VoronoiMST<long long> vo(N);
  for (int(i) = (0); (i) < (N); (i)++) {
    vo.G[i].emplace_back(N, a[i]);
    vo.G[N].emplace_back(i, a[i]);
  }
  for (int i = 0; i < M; i++) {
    LL x, y, z;
    cin >> x >> y >> z;
    x--, y--;
    vo.G[x].emplace_back(y, z);
    vo.G[y].emplace_back(x, z);
  }
  auto G = vo.build();
  Kruskal<long long> ks(N);
  for (int v = 0; v < N; v++) {
    for (auto e : G[v]) {
      int u = e.first;
      long long c = e.second;
      if (v < u) ks.add_edge(v, u, c);
    }
  }
  cout << ks.build() << endl;
}
int main() {
  solve_CF_529_F();
  return 0;
}
