#include <bits/stdc++.h>
using namespace std;
struct Edge {
  long long u, v, w;
  Edge() {}
  Edge(long long u, long long v, long long w) : u(u), v(v), w(w) {}
  friend bool operator<(Edge a, Edge b) { return a.w < b.w; }
};
const long long size = 1e5 + 5;
Edge edges[size];
long long val[size];
long long sum[size];
long long cnt[size];
long long fa[size];
long long find(long long x) {
  if (x == fa[x]) return x;
  long long f = find(fa[x]);
  sum[f] += sum[x];
  sum[x] = 0;
  cnt[f] += cnt[x];
  cnt[x] = 0;
  return fa[x] = f;
}
void merge(long long x, long long y) {
  long long fx = find(x), fy = find(y);
  if (fx == fy)
    cnt[fy]++;
  else {
    sum[fy] += sum[fx];
    sum[fx] = 0;
    cnt[fy] = cnt[fy] + cnt[fx] + 1;
    cnt[fx] = 0;
    fa[fx] = fy;
  }
}
int32_t main() {
  long long n, m;
  long long ans = 0;
  scanf("%lld%lld", &n, &m);
  for (long long i = 1; i <= n; i++)
    scanf("%lld", &val[i]), fa[i] = i, sum[i] = val[i];
  for (long long i = 1; i <= m; i++)
    scanf("%lld%lld%lld", &edges[i].u, &edges[i].v, &edges[i].w);
  sort(edges + 1, edges + 1 + m);
  for (long long i = 1; i <= m; i++) {
    long long x = edges[i].u, y = edges[i].v;
    merge(x, y);
    if (edges[i].w < sum[y]) {
      ans += cnt[y];
      cnt[y] = 0;
    }
  }
  printf("%lld\n", m - ans);
}
