#include <bits/stdc++.h>
using namespace std;
int n, m;
struct Edge {
  int v, u, w;
};
bool comp(Edge A, Edge B) { return A.w < B.w; }
vector<Edge> edges;
int ans;
int root[500000];
int cnt[500000];
int sz[500000];
long long s[500000];
int unused[500000];
int Root(int x) {
  if (x == root[x]) return x;
  return root[x] = Root(root[x]);
}
int Merge(Edge A) {
  int u = A.u, v = A.v, w = A.w;
  u = Root(u);
  v = Root(v);
  if (u == v) return 1;
  if (sz[u] > sz[v]) {
    v = v + u;
    u = v - u;
    v = v - u;
  }
  sz[v] += sz[u];
  s[v] += s[u];
  cnt[v] += cnt[u] + 1;
  root[u] = v;
  if (A.w <= s[v]) {
    ans += cnt[v];
    cnt[v] = 0;
  }
  return 0;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> s[i], sz[i] = 1, root[i] = i;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    edges.push_back({a, b, c});
  }
  sort((edges).begin(), (edges).end(), comp);
  for (int i = 0; i < m; i++) {
    unused[i] = Merge(edges[i]);
  }
  for (int i = 0; i < m; i++) {
    if (unused[i] && s[edges[i].u] >= edges[i].w) {
      ans++;
    }
  }
  cout << m - ans;
}
