#include <bits/stdc++.h>
using namespace std;
long long par[100005];
long long svertices[100005];
long long siz[100005];
long long bvertices[100005];
vector<long long int> v[100005];
long long a[100005];
long long int n, m;
vector<pair<long long, pair<long long, long long> > > vv;
int root(int A) {
  while (A != par[A]) {
    A = par[A];
  }
  return A;
}
void union1(int A, int B, long long int len) {
  int root_A = root(A);
  int root_B = root(B);
  if (root_A == root_B) {
    if (svertices[root_A] > len) {
      bvertices[root_A] = 0;
      return;
    } else {
      bvertices[root_A]++;
    }
    return;
  }
  long long sum = svertices[root_A] + svertices[root_B];
  if (sum > len) {
    if (siz[root_A] > siz[root_B]) {
      siz[root_A] += siz[root_B];
      bvertices[root_A] = 0;
      svertices[root_A] += svertices[root_B];
      par[root_B] = root_A;
    } else if (siz[root_A] <= siz[root_B]) {
      siz[root_B] += siz[root_A];
      bvertices[root_B] = 0;
      svertices[root_B] += svertices[root_A];
      par[root_A] = root_B;
    }
    return;
  } else {
    if (siz[root_A] > siz[root_B]) {
      siz[root_A] += siz[root_B];
      bvertices[root_A] += bvertices[root_B] + 1;
      svertices[root_A] += svertices[root_B];
      par[root_B] = root_A;
    } else if (siz[root_A] <= siz[root_B]) {
      siz[root_B] += siz[root_A];
      bvertices[root_B] += bvertices[root_A] + 1;
      svertices[root_B] += svertices[root_A];
      par[root_A] = root_B;
    }
    return;
  }
  return;
}
void initialise() {
  int i;
  for (i = 1; i <= n; i++) {
    siz[i] = 1;
    par[i] = i;
    bvertices[i] = 0;
    svertices[i] = a[i];
  }
}
int main() {
  cin >> n >> m;
  int i;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  initialise();
  long long int aa, bb, cc;
  for (i = 1; i <= m; i++) {
    cin >> aa >> bb >> cc;
    vv.push_back(make_pair(cc, make_pair(aa, bb)));
  }
  sort(vv.begin(), vv.end());
  for (i = 0; i < vv.size(); i++) {
    long long int X = vv[i].first;
    long long int YX = vv[i].second.first;
    long long int YY = vv[i].second.second;
    union1(YX, YY, X);
  }
  map<long long int, long long int> m;
  for (i = 1; i <= n; i++) {
    m[root(i)] = bvertices[root(i)];
  }
  long long int ans = 0;
  for (auto it = m.begin(); it != m.end(); it++) {
    ans += it->second;
  }
  cout << ans << endl;
}
