#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
long long x[maxn];
long long color[maxn], size[maxn], acc[maxn];
vector<pair<long long*, long long> > snap[maxn];
long long a[maxn], b[maxn], vi[maxn];
int find(int x) {
  if (color[x] == x) return x;
  return find(color[x]);
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> x[i];
  for (int i = 1; i <= n; i++) color[i] = 1, size[i] = 1, acc[i] = x[i];
  for (int i = 1; i <= m; i++) cin >> a[i] >> b[i] >> vi[i];
  vector<int> od(m);
  iota(od.begin(), od.end(), 1);
  sort(od.begin(), od.end(), [&](int a, int b) { return vi[a] < vi[b]; });
  for (int v : od) {
    int av = find(a[v]), bv = find(b[v]);
    if (color[av] != color[bv]) {
      if (size[av] < size[bv]) swap(av, bv);
      if (size[av] == size[bv]) {
        snap[v].push_back({&size[av], size[av]});
        size[av]++;
      }
      snap[v].push_back({&acc[av], acc[av]});
      acc[av] += acc[bv];
      snap[v].push_back({&acc[bv], acc[bv]});
      acc[bv] = 0;
      snap[v].push_back({&color[bv], color[bv]});
      color[bv] = av;
    }
  }
  reverse(od.begin(), od.end());
  int remove = 0;
  for (int v : od) {
    int av = find(a[v]), bv = find(b[v]);
    assert(av == bv);
    if (acc[av] < vi[v]) {
      remove++;
      for (auto it : snap[v]) *it.first = it.second;
    }
  }
  cout << remove << endl;
  return 0;
}
