#include <bits/stdc++.h>
using namespace std;
int n, m, ans, fa[500005], sz[500005], val[500005], sum[500005];
struct node {
  int x, y, d;
} a[500005];
inline bool cmp(node aa, node bb) { return aa.d < bb.d; }
int find(int x) {
  if (x == fa[x]) return x;
  fa[x] = find(fa[x]);
  sum[fa[x]] += sum[x];
  sz[fa[x]] += sz[x];
  sum[x] = sz[x] = 0;
  return fa[x];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &val[i]);
  for (int i = 1; i <= m; i++) scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].d);
  for (int i = 1; i <= n; i++) fa[i] = i, sum[i] = val[i];
  sort(a + 1, a + m + 1, cmp);
  for (int i = 1; i <= m; i++) {
    int fx = find(a[i].x);
    int fy = find(a[i].y);
    if (fx == fy) {
      sz[fx]++;
      if (a[i].d <= sum[fx]) ans += sz[fx], sz[fx] = 0;
    } else {
      fa[fx] = fy;
      sum[fy] += sum[fx];
      sz[fy] += sz[fx] + 1;
      sz[fx] = sum[fx] = 0;
      if (a[i].d <= sum[fy]) {
        ans += sz[fy];
        sz[fy] = 0;
      }
    }
  }
  printf("%d\n", m - ans);
  return 0;
}
