#include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

class UnionFind {
private:
  vector<ll> data;

public:
  UnionFind(ll n): data(n, -1) {}

  ll size(ll i) { return -data[find(i)]; }
  bool root(ll i) { return data[i] < 0; }
  bool same(ll i, ll j) { return find(i) == find(j); }

  ll find(ll i) { return root(i) ? i : (data[i] = find(data[i])); }

  bool unite(ll i, ll j) {
    if(same(i, j)) return false;
    data[find(i)] += data[find(j)];
    data[find(j)] = find(i);
    return true;
  }
};

int main(void) {
  ll N, M;
  cin >> N >> M;
  vector<ll> W(N);
  REP(i, 0, N) cin >> W[i];
  vector<ll> U(M), V(M), Y(M);
  REP(i, 0, M) cin >> U[i] >> V[i] >> Y[i], U[i]--, V[i]--;

  vector<ll> ord(M);
  REP(i, 0, M) ord[i] = i;
  sort(ord.begin(), ord.end(), [&](const ll i, const ll j) { return Y[i] < Y[j]; });

  ll ans = 0;
  vector<ll> sum(W), cnt(N, 0);
  UnionFind uf(N);

  for (ll i : ord) {
    if (!uf.same(U[i], V[i])) {
      sum[uf.find(U[i])] += sum[uf.find(V[i])];
      cnt[uf.find(U[i])] += cnt[uf.find(V[i])];
      cnt[uf.find(U[i])]++;
      uf.unite(U[i], V[i]);
    } else {
      cnt[uf.find(U[i])]++;
    }

    if (sum[uf.find(U[i])] >= Y[i]) {
      ans += cnt[uf.find(U[i])];
      cnt[uf.find(U[i])] = 0;
    }
  }

  cout << M - ans << endl;
}