#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using T = tuple<ll, int, int>;
struct UnionFind {
  vector<int> data;
  UnionFind(int sz) : data(sz, -1) {}
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    bool is_union = (x != y);
    if (is_union) {
      if (data[x] > data[y]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return is_union;
  }
  int find(int x) {
    if (data[x] < 0) {
      return x;
    } else {
      data[x] = find(data[x]);
      return data[x];
    }
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -data[find(x)]; }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<ll> x(n);
  for (int i = 0; i < n; i++) cin >> x[i];
  vector<T> es;
  for (int i = 0; i < m; i++) {
    int a, b;
    ll y;
    cin >> a >> b >> y;
    a--;
    b--;
    es.emplace_back(y, a, b);
  }
  sort(es.begin(), es.end());
  int ok = 0, ng = m + 1;
  while (ng - ok > 1) {
    int mid = (ok + ng) / 2;
    vector<ll> node_sum(n, 0);
    for (int i = 0; i < n; i++) node_sum[i] = x[i];
    vector<ll> edge_max(n, 0);
    UnionFind uf(n);
    for (int i = 0; i < mid; i++) {
      ll cost;
      int a, b;
      tie(cost, a, b) = es[i];
      if (uf.same(a, b)) {
        int r = uf.find(a);
        edge_max[r] = max(edge_max[r], cost);
      } else {
        int ra = uf.find(a), rb = uf.find(b);
        uf.unite(a, b);
        int r = uf.find(a);
        if (r == ra) {
          node_sum[r] += node_sum[rb];
          node_sum[rb] = 0;
          edge_max[r] = max({cost, edge_max[r], edge_max[rb]});
          edge_max[rb] = 0;
        } else {
          node_sum[r] += node_sum[ra];
          node_sum[ra] = 0;
          edge_max[r] = max({cost, edge_max[r], edge_max[ra]});
          edge_max[ra] = 0;
        }
      }
    }
    bool flag = true;
    for (int i = 0; i < n; i++) {
      if (uf.find(i) != i) continue;
      if (node_sum[i] < edge_max[i]) {
        flag = false;
        break;
      }
    }
    (flag ? ok : ng) = mid;
  }
  cout << m - ok << endl;
  return 0;
}
