#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
  vector<int> data;
  UnionFind(int sz) { data.assign(sz, -1); }
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return (false);
    if (data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
  int find(int k) {
    if (data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
  int size(int k) { return (-data[find(k)]); }
};
int main() {
  int n, m;
  cin >> n >> m;
  long long x[n];
  for (int i = 0; i < n; i++) cin >> x[i];
  long long a[m], b[m], y[m];
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> y[i];
    a[i]--;
    b[i]--;
  }
  bool need[m];
  for (int i = 0; i < m; i++) need[i] = true;
  bool update = true;
  while (update) {
    update = false;
    UnionFind uf(n);
    for (int i = 0; i < m; i++) {
      if (need[i]) uf.unite(a[i], b[i]);
    }
    long long weight[n];
    for (int i = 0; i < n; i++) weight[i] = 0;
    for (int i = 0; i < n; i++) {
      weight[uf.find(i)] += x[i];
    }
    for (int i = 0; i < m; i++) {
      if (need[i]) {
        if (weight[uf.find(a[i])] < y[i]) {
          need[i] = false;
          update = true;
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < m; i++)
    if (!need[i]) ans++;
  cout << ans << endl;
  return 0;
}
