#include <bits/stdc++.h>
using namespace std;
int n, m;
long x[1 << 17];
struct UF {
  int n;
  vector<int> parent, rank;
  vector<long> w;
  UF(int n_ = 0) : n(n_), parent(n_), rank(n_, 0), w(n_) {
    for (int i = 0; i < n_; i++) {
      parent[i] = i;
      w[i] = x[i];
    }
  }
  int find(int a) { return parent[a] != a ? parent[a] = find(parent[a]) : a; }
  bool same(int a, int b) { return find(a) == find(b); }
  bool unite(int a, int b) {
    a = find(a), b = find(b);
    if (a == b) return false;
    if (rank[a] < rank[b]) {
      parent[a] = b;
      w[b] += w[a];
    } else {
      parent[b] = a;
      w[a] += w[b];
      if (rank[a] == rank[b]) rank[a]++;
    }
    return true;
  }
};
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> x[i];
  vector<pair<long, pair<int, int> > > G[2];
  int id = 0;
  for (int i = 0; i < m; i++) {
    long y;
    int u, v;
    cin >> u >> v >> y;
    G[id].push_back(make_pair(y, make_pair(u - 1, v - 1)));
  }
  int now = 1;
  while (now) {
    now = 0;
    int next = id ? 0 : 1;
    G[next].clear();
    UF uf(n);
    for (int i = 0; i < G[id].size(); i++) {
      uf.unite(G[id][i].second.first, G[id][i].second.second);
    }
    for (int i = 0; i < G[id].size(); i++) {
      if (uf.w[uf.find(G[id][i].second.first)] >= G[id][i].first) {
        G[next].push_back(G[id][i]);
      } else
        now = 1;
    }
    id = next;
  }
  cout << m - G[id].size() << endl;
}
