#include <bits/stdc++.h>
using namespace std;
class UnionFind {
 private:
  vector<long long> parent, rank, size, val, sm;

 public:
  UnionFind(long long n, vector<long long>& _val) {
    rank.assign(n, 0);
    parent.assign(n, 0);
    size.assign(n, 1);
    val = _val;
    sm.assign(n, 0);
    for (int i = 0; i < n; i++) sm[i] = val[i];
    for (int i = 0; i < n; i++) parent[i] = i;
  }
  long long findSet(long long i) {
    if (parent[i] == i)
      return i;
    else
      return parent[i] = findSet(parent[i]);
  }
  bool isSameSet(long long i, long long j) { return findSet(i) == findSet(j); }
  void unionSet(long long i, long long j) {
    if (!isSameSet(i, j)) {
      long long x = findSet(i);
      long long y = findSet(j);
      if (rank[x] < rank[y]) {
        parent[x] = y;
        size[y] += size[x];
        sm[y] += sm[x];
      } else {
        parent[y] = x;
        size[x] += size[y];
        sm[x] += sm[y];
        if (rank[x] == rank[y]) rank[x]++;
      }
    }
  }
  long long sizeOfSet(long long i) { return size[findSet(i)]; }
  long long smSet(long long i) { return sm[findSet(i)]; }
};
vector<long long> x, ok, _, vis;
vector<pair<long long, pair<long long, long long> > > e;
vector<vector<pair<long long, long long> > > edges;
vector<pair<long long, long long> > __;
long long cur = 0;
long long dfs(long long v) {
  for (auto& u : edges[v]) {
    if (u.second >= cur && vis[u.second] == 0) {
      vis[u.second] = 1;
      ok[u.second] = 2;
      dfs(u.first);
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  long long m, n;
  cin >> n >> m;
  x.assign(n, 0);
  for (int i = 0; i < n; i++) cin >> x[i];
  e.assign(m, {0, {0, 0}});
  for (int i = 0; i < m; i++) {
    cin >> e[i].second.first >> e[i].second.second >> e[i].first;
    e[i].second.first--;
    e[i].second.second--;
  }
  sort(e.begin(), e.end());
  reverse(e.begin(), e.end());
  UnionFind uf(n, x);
  ok.assign(m, 0);
  for (int i = m - 1; i >= 0; i--) {
    uf.unionSet(e[i].second.first, e[i].second.second);
    if (uf.smSet(e[i].second.first) > e[i].first) ok[i] = 1;
  }
  edges.assign(n, __);
  for (int i = 0; i < m; i++) {
    edges[e[i].second.first].push_back({e[i].second.second, i});
    edges[e[i].second.second].push_back({e[i].second.first, i});
  }
  long long res = 0;
  vis.assign(m, 0);
  for (int i = 0; i < m; i++) {
    if (ok[i] == 0) res++;
    if (ok[i] == 1) {
      vis[i] = 1;
      dfs(e[i].second.first);
      dfs(e[i].second.second);
    }
    cur++;
  }
  cout << res << endl;
}
