#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 1LL << 30;
const ll LINF = 1LL << 60;
const double eps = 1e-5;
const ll MOD = 1000000007LL;
template <typename T>
void chmin(T &a, T b) {
  a = min(a, b);
};
template <typename T>
void chmax(T &a, T b) {
  a = max(a, b);
};
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
vector<ll> x;
struct UnionFind {
  vector<int> par, siz, sum, co;
  UnionFind(int n) {
    par.resize(n);
    siz.resize(n, 1);
    sum.resize(n);
    co.resize(n);
    for (int i = 0; i < n; i++) {
      sum[i] = x[i];
      par[i] = i;
    }
  }
  int find(int x) {
    if (par[x] == x) {
      return x;
    } else {
      return par[x] = find(par[x]);
    }
  }
  bool unite(int u, int v) {
    u = find(u), v = find(v);
    if (u == v) return false;
    if (siz[u] < siz[v]) swap(u, v);
    par[v] = u;
    siz[u] += siz[v];
    sum[u] += sum[v];
    co[u] += co[v];
    return true;
  }
  bool same(int u, int v) { return find(u) == find(v); }
};
int main() {
  int n, m;
  cin >> n >> m;
  x.resize(n);
  for (int i = 0; i < n; i++) cin >> x[i];
  vector<pair<ll, P>> v;
  for (int i = 0; i < m; i++) {
    int a, b, y;
    cin >> a >> b >> y;
    --a;
    --b;
    v.push_back(make_pair(y, make_pair(a, b)));
  }
  sort(v.begin(), v.end());
  UnionFind uf(n);
  int ans = 0;
  for (int i = 0; i < m; i++) {
    int a = v[i].second.first, b = v[i].second.second;
    ll y = v[i].first;
    uf.unite(a, b);
    uf.co[uf.find(a)]++;
    if (uf.sum[uf.find(a)] >= y) {
      ans += uf.co[uf.find(a)];
      uf.co[uf.find(a)] = 0;
    }
  }
  cout << m - ans << endl;
  return 0;
}
