#include <bits/stdc++.h>
using namespace std;
class Vertex {
 public:
  long long v;
  int i;
  Vertex();
  Vertex(long long v, int i);
  bool operator<(const Vertex& next) const;
};
Vertex::Vertex() {}
Vertex::Vertex(long long v, int i) {
  this->v = v;
  this->i = i;
}
bool Vertex::operator<(const Vertex& next) const { return this->v > next.v; }
class Edge {
 public:
  int x;
  int y;
  long long v;
  Edge();
  Edge(long long v, int x, int y);
  bool operator<(const Edge& next) const;
};
Edge::Edge() {}
Edge::Edge(long long v, int x, int y) {
  this->v = v;
  this->x = x;
  this->y = y;
}
bool Edge::operator<(const Edge& next) const { return this->v > next.v; }
bool visited[200100];
long long values[200100];
vector<vector<int>> offer(200100);
vector<vector<long long>> weight(200100);
priority_queue<Vertex> p;
priority_queue<Edge> p1;
int main() {
  int n, m, x, y, c = 0;
  long long w, x1, y1, l = 0;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &values[i]);
    p.emplace(values[i], i);
  }
  for (int i = 0; i < m; i++) {
    scanf("%d %d %lld", &x, &y, &w);
    offer[x - 1].push_back(y - 1);
    offer[y - 1].push_back(x - 1);
    weight[x - 1].push_back(w);
    weight[y - 1].push_back(w);
  }
  x1 = LLONG_MAX;
  for (int i = 0; i < n - 1; i++) {
    visited[c] = true;
    if (values[c] < x1) {
      x1 = values[c];
      y1 = c;
    }
    for (int j = 0; j < offer[c].size(); j++) {
      if (visited[offer[c][j]]) continue;
      p1.emplace(weight[c][j], c, offer[c][j]);
    }
    while (visited[p.top().i]) p.pop();
    while (!p1.empty() && visited[p1.top().y]) p1.pop();
    if (p1.empty() || p.top().v + values[y1] < p1.top().v) {
      l += p.top().v + values[y1];
      c = p.top().i;
      p.pop();
    } else {
      l += p1.top().v;
      c = p1.top().y;
      p1.pop();
    }
  }
  printf("%lld\n", l);
}
