#include <bits/stdc++.h>
using namespace std;
long long INF = 1e16 + 7;
long long mod = 1e9 + 7;
long long dx[4] = {1, 0, -1, 0};
long long dy[4] = {0, 1, 0, -1};
struct UnionFind {
  vector<long long> par;
  vector<pair<long long, long long>> size;
  UnionFind(long long x, vector<long long> y) {
    par.resize(x);
    size.resize(x);
    for (long long i = 0; i < x; i++) {
      par[i] = i;
    }
    for (long long i = 0; i < x; i++) {
      size[i].second = y[i];
    }
  }
  long long find(long long x) {
    if (par[x] == x) return x;
    return par[x] = find(par[x]);
  }
  bool same(long long x, long long y) { return find(x) == find(y); }
  pair<long long, long long> consize(long long x) {
    return {size[find(x)].first, size[find(x)].second};
  }
  void unite(long long x, long long y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (size[x] < size[y]) {
      par[x] = y;
      size[y].first += size[x].first;
      size[y].second += size[x].second;
    } else {
      par[y] = x;
      size[x].first += size[y].first;
      size[x].second += size[y].second;
    }
  }
};
signed main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> X(N);
  long long sum = 0;
  for (long long i = 0; i < N; i++) {
    cin >> X[i];
    sum += X[i];
  }
  vector<pair<long long, pair<long long, long long>>> hen(M);
  for (long long i = 0; i < M; i++) {
    cin >> hen[i].second.first >> hen[i].second.second >> hen[i].first;
    hen[i].second.first--;
    hen[i].second.second--;
  }
  sort(hen.begin(), hen.end());
  UnionFind uf(N, X);
  vector<long long> ok(N);
  for (long long i = 0; i < M; i++) {
    long long x = uf.find(hen[i].second.first);
    long long y = uf.find(hen[i].second.second);
    uf.unite(hen[i].second.first, hen[i].second.second);
    uf.size[uf.find(hen[i].second.first)].first++;
    if (uf.consize(hen[i].second.first).second >= hen[i].first) {
      ok[x] = 0;
      ok[y] = 0;
      ok[uf.find(hen[i].second.first)] = uf.consize(hen[i].second.first).first;
    }
  }
  long long cnt = 0;
  for (long long i = 0; i < N; i++) {
    cnt += ok[i];
  }
  cout << M - cnt << endl;
}
