#include <bits/stdc++.h>
using namespace std;
int dsu[100005];
int w[100005];
int pend[100005];
int findp(int i) { return (dsu[i] < 0) ? i : (dsu[i] = findp(dsu[i])); }
void merge(int i, int j) {
  if ((i = findp(i)) != (j = findp(j))) {
    if (dsu[i] > dsu[j]) {
      swap(i, j);
    }
    w[i] += w[j];
    pend[i] += pend[j];
    dsu[i] += dsu[j];
    dsu[j] = i;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << setprecision(11);
  int n, m;
  cin >> n >> m;
  for (long long i = 0, _n = (100005); i < _n; i++) dsu[i] = -1;
  for (long long i = 0, _n = (n); i < _n; i++) {
    cin >> w[i + 1];
  }
  vector<pair<int, pair<int, int>>> edges;
  for (long long i = 0, _n = (m); i < _n; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    edges.push_back(make_pair(c, make_pair(a, b)));
  }
  sort(edges.begin(), edges.end());
  int ans = 0;
  for (int i = 0; i < m; i++) {
    merge(edges[i].second.first, edges[i].second.second);
    int comp = findp(edges[i].second.first);
    pend[comp]++;
    if (w[comp] >= edges[i].first) {
      ans += pend[comp];
      pend[comp] = 0;
    }
  }
  cout << m - ans;
  return 0;
}
