#include <bits/stdc++.h>
using namespace std;
class UnionFind {
  vector<int> par;
  vector<int> rank;
  vector<long long> weight;

 public:
  UnionFind(int max_n) : par(max_n), rank(max_n), weight(max_n) {}
  void init(int n, int w[]) {
    for (int i = 0; i < n; i++) {
      par[i] = i;
      rank[i] = 0;
      weight[i] = w[i];
    }
  }
  int find(int x) {
    if (par[x] == x) return x;
    return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (rank[x] < rank[y]) {
      par[x] = y;
      weight[y] += weight[x];
    } else {
      par[y] = x;
      weight[x] += weight[y];
      if (rank[x] == rank[y]) rank[x]++;
    }
  }
  bool same(int x, int y) { return find(x) == find(y); }
  long long wei(int u) { return weight[find(u)]; }
};
int n, m;
int x[100000];
set<tuple<int, int, int>> edges;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < (int)(n); i++) cin >> x[i];
  for (int i = 0; i < (int)(m); i++) {
    int a, b, y;
    cin >> a >> b >> y;
    a--;
    b--;
    edges.emplace(y, a, b);
  }
  UnionFind uf(n);
  while (1) {
    uf.init(n, x);
    for (auto p : edges) {
      int y, a, b;
      tie(y, a, b) = p;
      if (!uf.same(a, b)) {
        uf.unite(a, b);
      }
    }
    bool f = true;
    for (auto it = edges.begin(); it != edges.end();) {
      int y, a, b;
      tie(y, a, b) = *it;
      if (uf.wei(a) < y) {
        it = edges.erase(it);
        f = false;
      } else {
        ++it;
      }
    }
    if (f) break;
  }
  cout << m - edges.size() << endl;
  return 0;
}
