#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
  long long n;
  vector<long long> ran, sum, p, cnt, MIN;
  UnionFind() {}
  UnionFind(long long sz)
      : sum(sz, 0), n(sz), ran(sz, 1), p(sz, 0), MIN(sz, 1e17) {
    iota(p.begin(), p.end(), 0);
  }
  long long find(long long x) { return (x == p[x] ? x : p[x] = find(p[x])); }
  bool same(long long x, long long y) { return find(x) == find(y); }
  long long num(long long x) { return sum[find(x)]; }
  long long mini(long long x) { return MIN[find(x)]; }
  void unite(long long x, long long y, long long A) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (ran[x] < ran[y]) swap(x, y);
    sum[x] += sum[y];
    ran[x] += ran[y];
    MIN[x] = min(MIN[x], MIN[y]);
    p[y] = x;
  }
  long long SUM(long long x) { return ran[find(x)]; }
};
vector<pair<long long, long long> > v[200000];
signed main() {
  long long n, m;
  cin >> n >> m;
  UnionFind U(n);
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    U.sum[i] = x;
  }
  long long a[m], b[m], c[m];
  for (long long i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--;
    b[i]--;
    v[a[i]].push_back(pair<long long, long long>(b[i], c[i]));
    v[b[i]].push_back(pair<long long, long long>(a[i], c[i]));
  }
  for (long long i = 0; i < n; i++) {
    queue<long long> q;
    q.push(i);
    while (!q.empty()) {
      long long now = q.front();
      q.pop();
      for (long long j = 0; j < v[now].size(); j++) {
        long long nex = v[now][j].first;
        long long cost = v[now][j].second;
        if (U.same(now, nex)) continue;
        if (U.num(now) >= cost) {
          q.push(nex);
          U.unite(nex, i, 0);
        }
      }
    }
  }
  for (long long ppp = 0; ppp < 10; ppp++)
    for (long long i = 0; i < n; i++) {
      long long weight = U.num(i);
      long long sum = 0;
      set<long long> st;
      map<long long, long long> M, M2;
      vector<pair<long long, pair<long long, long long> > > A;
      vector<long long> B;
      for (long long j = 0; j < v[i].size(); j++) {
        long long nex = v[i][j].first;
        long long cost = v[i][j].second;
        if (U.same(nex, i)) continue;
        if (!st.count(U.find(nex))) {
          B.push_back(U.find(nex));
          M[U.find(nex)] = U.num(nex);
          M2[U.find(nex)] = cost;
        } else {
          M2[U.find(nex)] = min(M2[U.find(nex)], cost);
        }
      }
      for (long long j = 0; j < B.size(); j++) {
        A.push_back(pair<long long, pair<long long, long long> >(
            M2[B[j]], pair<long long, long long>(M[B[j]], B[j])));
        sum += M[B[j]];
      }
      sort(A.begin(), A.end());
      for (long long j = A.size() - 1; j >= 0; j--) {
        if (sum + weight < A[j].first) {
          sum -= A[j].second.first;
          continue;
        }
        for (long long k = j; k >= 0; k--) {
          U.unite(i, A[k].second.second, (long long)0);
        }
        break;
      }
    }
  long long ANS = 0;
  for (long long i = 0; i < m; i++) {
    long long x = a[i];
    long long y = b[i];
    if (U.same(x, y) && U.num(x) >= c[i]) continue;
    ANS++;
  }
  cout << ANS << endl;
}
