#include <bits/stdc++.h>
using namespace std;
long long int n, m;
long long int x[114514];
long long int a[114514], b[114514], y[114514];
vector<vector<long long int> > adjlist;
vector<vector<long long int> > wlist;
vector<set<pair<long long int, long long int> > > adjinfo;
long long int conn_id[114514];
long long int num_conn;
vector<long long int> weight_conn;
long long int theta = INT_MAX;
vector<int> alive;
vector<int> get_connectivity() {
  for (int i = 0; i < n; i++) conn_id[i] = -1;
  int num_conn = 0;
  for (int i = 0; i < n; i++) {
    if (conn_id[i] == -1) {
      conn_id[i] = num_conn;
      queue<long long int> q;
      q.push(i);
      while (!q.empty()) {
        int t = q.front();
        q.pop();
        for (pair<long long int, long long int> info : adjinfo[t]) {
          int t2 = info.first;
          if (conn_id[t2] == -1) {
            conn_id[t2] = num_conn;
            q.push(t2);
          }
        }
      }
      num_conn++;
    }
  }
  weight_conn = vector<long long int>(num_conn);
  for (int i = 0; i < n; i++) {
    weight_conn[conn_id[i]] += x[i];
  }
  vector<int> ans;
  for (int i = 0; i < m; i++) {
    if (!alive[i]) continue;
    if (weight_conn[conn_id[a[i]]] < y[i]) {
      ans.push_back(i);
    }
  }
  return ans;
}
int main(void) {
  cin >> n >> m;
  alive = vector<int>(m, 1);
  adjinfo = vector<set<pair<long long int, long long int> > >(n);
  for (int i = 0; i < n; i++) cin >> x[i];
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d", &a[i], &b[i], &y[i]);
    a[i]--;
    b[i]--;
    adjinfo[a[i]].insert(make_pair(b[i], y[i]));
    adjinfo[b[i]].insert(make_pair(a[i], y[i]));
  }
  int ans = 0;
  while (1) {
    vector<int> invalid_edge = get_connectivity();
    if (invalid_edge.empty()) break;
    ans += invalid_edge.size();
    for (int i : invalid_edge) {
      alive[i] = 0;
      adjinfo[a[i]].erase(make_pair(b[i], y[i]));
      adjinfo[b[i]].erase(make_pair(a[i], y[i]));
    }
  }
  cout << ans << endl;
  return 0;
}
