#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct unionfind {
  vector<int> par, t;
  vector<ll> s;
  unionfind(int n) : par(n, -1), s(n), t(n) {}
  int find(int x) {
    if (par[x] < 0)
      return x;
    else
      return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    s[x] += s[y];
    t[x] += t[y];
    par[y] = x;
  }
  int size(int x) { return -par[find(x)]; }
  int val(int x) { return s[find(x)]; }
  bool same(int x, int y) { return find(x) == find(y); }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<ll> x(n), y(m);
  vector<pair<ll, pair<int, int>>> p(m);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b >> y[i];
    a--, b--;
    p[i] = {y[i], {a, b}};
  }
  sort(p.begin(), p.end());
  unionfind dsu(n);
  for (int i = 0; i < n; i++) {
    dsu.s[i] = x[i];
  }
  int ans = 0;
  for (int i = 0; i < m; i++) {
    int a, b;
    tie(a, b) = p[i].second;
    dsu.unite(a, b);
    dsu.t[dsu.find(a)]++;
    if (dsu.val(a) >= p[i].first) {
      ans += dsu.t[dsu.find(a)];
      dsu.t[dsu.find(a)] = 0;
    }
  }
  cout << m - ans << endl;
  return 0;
}
