#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define N 100005

struct Edge{
  int u, v, w;
}edge[N];

bool cmp(Edge a, Edge b) {
  return a.w < b.w;
}

int p[N], sub[N], ans[N];
LL val[N];

int root(int u) {
  while(u != p[u]) {
    p[u] = p[p[u]];
    u = p[u];
  }
  return u;
}
void merge(int uu, int vv, int wt) {
  int u = root(uu), v = root(vv);
  if (u == v) {
    if (val[u] < wt) ans[u]++;
    return;
  }
  p[v] = u;
  sub[u] += sub[v];
  val[u] += val[v];
  if (wt * 1LL <= val[u]) {
    ans[u] = 0;
  } else ans[u] = ans[u] + ans[v] + 1;
}

int main() {
  int n, i, m;
  cin >> n >> m;
  for (i=1;i<=n;i++) {
    cin >> val[i];
    p[i] = i;
    sub[i] = 1;
    ans[i] = 0;
  }
  for (i=0;i<m;i++) {
    cin >> edge[i].u >> edge[i].v >> edge[i].w;
  }
  sort(edge, edge + m, cmp);
  for (i=0;i<m;i++) {
    merge(edge[i].u, edge[i].v, edge[i].w);
  }
  int res = 0;
  for (i=1;i<=n;i++) if (p[i] == i) res += ans[i];
  cout << res << '\n';

  return 0;
}
