#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
struct edge {
  int u, v, w;
  bool operator<(const edge& o) const { return w < o.w; }
} e[N];
int n, m, a[N], f[N];
long long sum[N], p[N];
int getf(int x) { return f[x] == x ? x : f[x] = getf(f[x]); }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) f[i] = i, sum[i] = a[i];
  for (int i = 1; i <= m; i++) scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
  sort(e + 1, e + 1 + m);
  for (int i = 1; i <= m; i++) {
    int fu = getf(e[i].u), fv = getf(e[i].v);
    if (fu == fv) {
      f[fu] = fv;
      sum[fv] += sum[fu];
      p[fv] += p[fu];
    }
    p[fv]++;
    if (e[i].w <= sum[fv]) p[fv] = 0;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (getf(i) == i) ans += p[i];
  printf("%d\n", ans);
}
