#include <bits/stdc++.h>
using namespace std;
struct UF {
  vector<long long> par;
  vector<long long> sz;
  vector<long long> rank;
  vector<long long> val;
  UF(int n) : par(n), sz(n), rank(n), val(n) {
    for (int i = 0; i < n; i++) {
      par[i] = i;
      sz[i] = 1;
      rank[i] = 0;
      val[i] = 0;
    }
  }
  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];
      val[y] += val[x];
    } else {
      par[y] = x;
      sz[x] += sz[y];
      val[x] += val[y];
      if (rank[x] == rank[y]) rank[x]++;
    }
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int n) { return sz[find(n)]; }
};
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> x(n);
  for (long long(i) = (0); (i) < (n); ++i) cin >> x[i];
  vector<pair<long long, pair<long long, long long>>> v;
  for (long long(i) = (0); (i) < (m); ++i) {
    long long a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    v.push_back(make_pair(c, make_pair(a, b)));
  }
  sort(v.begin(), v.end());
  UF uf(n);
  for (long long(i) = (0); (i) < (n); ++i) uf.val[i] = x[i];
  vector<pair<long long, long long>> mp;
  for (long long(i) = (0); (i) < (m); ++i) {
    long long a = v[i].second.first;
    long long b = v[i].second.second;
    if (!uf.same(a, b)) {
      uf.unite(a, b);
      mp.push_back(make_pair(i, uf.val[uf.find(a)]));
    }
  }
  UF uf2(n);
  for (long long(i) = (0); (i) < (n); ++i) uf2.val[i] = x[i];
  for (long long i = mp.size() - 1; i >= 0; i--) {
    long long id = mp[i].first;
    long long a = v[id].second.first;
    long long b = v[id].second.second;
    long long cost = v[id].first;
    long long seica = mp[i].second;
    if (uf2.same(a, b)) continue;
    if (cost <= seica || cost <= uf2.val[uf2.find(a)] + uf2.val[uf2.find(b)]) {
      uf2.unite(a, b);
    }
  }
  long long ans = 0;
  for (long long(i) = (0); (i) < (m); ++i) {
    long long a = v[i].second.first;
    long long b = v[i].second.second;
    long long cost = v[i].first;
    if (!uf2.same(a, b)) {
      if (uf2.val[uf2.find(a)] + uf2.val[uf2.find(b)] >= cost) {
        uf2.unite(a, b);
      }
    }
    if (!uf2.same(a, b) || cost > uf2.val[uf2.find(a)]) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
