#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const int INF = (long long)1e9 + 5;
struct Edge {
  int a, b, w;
  bool operator<(const Edge &e) const { return w < e.w; }
};
struct DSU {
  int N, pa[MAXN], sz[MAXN];
  long long sum[MAXN];
  vector<int> who[MAXN];
  void init(int _N, int *x) {
    N = _N;
    for (int i = 1; i <= N; i++) {
      pa[i] = i;
      sz[i] = 1;
      sum[i] = x[i];
    }
  }
  int find(int x) { return x == pa[x] ? x : pa[x] = find(pa[x]); }
  void merge(int x, int y) {
    x = find(x);
    y = find(y);
    if (sz[x] < sz[y]) swap(x, y);
    if (x == y) {
      who[x].push_back(-1);
    } else {
      who[x].push_back(y);
      sum[x] += sum[y];
      sz[x] += sz[y];
      pa[y] = x;
    }
  }
  void undo(int x) {
    x = find(x);
    if (who[x].back() != -1) {
      int y = who[x].back();
      pa[y] = y;
      sum[x] -= sum[y];
      sz[x] -= sz[y];
    }
    who[x].pop_back();
  }
} dsu;
int N, M, x[MAXN];
Edge es[MAXN];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> M;
  for (int i = 1; i <= N; i++) {
    cin >> x[i];
  }
  for (int i = 0; i < M; i++) {
    int a, b, w;
    cin >> a >> b >> w;
    es[i] = {a, b, w};
  }
  dsu.init(N, x);
  sort(es, es + M);
  for (int i = 0; i < M; i++) {
    dsu.merge(es[i].a, es[i].b);
  }
  int ans = 0;
  for (int i = M - 1; i >= 0; i--) {
    int root = dsu.find(es[i].a);
    if (dsu.sum[root] < es[i].w) {
      ans++;
      dsu.undo(root);
    }
  }
  cout << ans << "\n";
  return 0;
}
