#include <bits/stdc++.h>
using namespace std;
int n, m, ans;
int w[100000 + 5], fa[100000 + 5], cnt[100000 + 5];
struct edge {
  int u, v, w;
} a[100000 + 5];
bool cmp(edge s1, edge s2) { return s1.w < s2.w; }
int xfind(int x) { return (fa[x] == x) ? x : xfind(fa[x]); }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &w[i]);
    fa[i] = i;
  }
  for (int i = 1; i <= m; i++) scanf("%d%d%d", &a[i].u, &a[i].v, &a[i].w);
  sort(a + 1, a + m + 1, cmp);
  for (int i = 1; i <= m; i++) {
    int x = xfind(a[i].u), y = xfind(a[i].v);
    if (x != y) {
      w[x] += w[y];
      cnt[x] += cnt[y];
      w[y] = 0, cnt[y] = 0;
      fa[y] = x;
    }
    cnt[x]++;
    if (w[x] >= a[i].w) {
      ans += cnt[x];
      cnt[x] = 0;
    }
  }
  printf("%d", m - ans);
}
