#include <bits/stdc++.h>
using namespace std;
void printV(vector<int> v) {
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << '\n';
}
void print2V(vector<vector<int> > v) {
  for (int i = 0; i < v.size(); i++) {
    for (int j = 0; j < v[i].size(); j++) {
      cout << v[i][j] << " ";
    }
    cout << '\n';
  }
}
long long n, m;
long long dsu[100010], weight[100010], cnt[100010];
vector<pair<long long, pair<long long, long long> > > edges;
long long root(long long a) {
  if (dsu[a] != a) {
    dsu[a] = root(dsu[a]);
  }
  return dsu[a];
}
int main() {
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    cin >> weight[i];
    dsu[i] = i;
  }
  long long a, b, w;
  for (long long i = 0; i < m; i++) {
    cin >> a >> b >> w;
    edges.push_back(make_pair(w, make_pair(a - 1, b - 1)));
  }
  sort(edges.begin(), edges.end());
  long long good_edges = 0;
  for (long long i = 0; i < m; i++) {
    w = edges[i].first;
    a = root(edges[i].second.first);
    b = root(edges[i].second.second);
    if (a != b) {
      dsu[a] = b;
      weight[b] = min(weight[b] + weight[a], (long long)1e16);
      cnt[b] += cnt[a];
    }
    cnt[b]++;
    if (weight[b] > w) {
      good_edges += cnt[b];
      cnt[b] = 0;
    }
  }
  cout << m - good_edges;
}
