#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int> X(N), A(M), B(M), C(M);
  for (int i = 0; i < N; ++i) {
    cin >> X[i];
  }
  for (int i = 0; i < M; ++i) {
    cin >> A[i] >> B[i] >> C[i];
    --A[i], --B[i];
  }
  vector<int> perm(M);
  for (int i = 0; i < M; ++i) {
    perm[i] = i;
  }
  sort(perm.begin(), perm.end(), [&](int i, int j) { return C[i] < C[j]; });
  vector<int> fA(M), fB(M), fC(M);
  for (int i = 0; i < M; ++i) {
    fA[i] = A[perm[i]];
    fB[i] = B[perm[i]];
    fC[i] = C[perm[i]];
  }
  A = fA;
  B = fB;
  C = fC;
  vector<vector<int> > g(N), cg(N), sg(N);
  vector<int> root(N), croot(N);
  vector<long long> cost(N), ccost(N);
  for (int i = 0; i < N; ++i) {
    g[i].push_back(i);
    cg[i].push_back(i);
    sg[i].push_back(i);
    root[i] = i;
    croot[i] = i;
    cost[i] = X[i];
    ccost[i] = X[i];
  }
  for (int i = 0; i < M; ++i) {
    int a = root[A[i]], b = root[B[i]];
    if (a == b) continue;
    if (g[a].size() < g[b].size()) {
      swap(A[i], B[i]);
    }
    for (int j : g[b]) {
      root[j] = a;
    }
    cost[a] += cost[b];
    g[a].insert(g[a].end(), g[b].begin(), g[b].end());
    g[b].clear();
    cg[a].insert(cg[a].end(), cg[b].begin(), cg[b].end());
    if (cost[a] >= C[i]) {
      for (int j : cg[a]) {
        if (j == a) continue;
        for (int k : sg[j]) croot[k] = a;
        sg[a].insert(sg[a].end(), sg[j].begin(), sg[j].end());
        ccost[a] += ccost[j];
        sg[j].clear();
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < M; ++i) {
    if (croot[A[i]] == croot[B[i]] && ccost[croot[A[i]]] >= C[i]) {
      ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}
