#include <bits/stdc++.h>
int fa[101000];
int v[101000];
bool used[101000], ok[101000], del[101000];
int h[101000], nxt[2 * 101000], to[2 * 101000], K = 1;
void ins(int u, int v) {
  nxt[++K] = h[u];
  h[u] = K;
  to[K] = v;
}
struct xxx {
  int x, y, c;
} e[101000];
int Find(int x) { return fa[x] == x ? x : fa[x] = Find(fa[x]); }
bool cmp(xxx a, xxx b) { return a.c < b.c; }
void dfs(int x, int now) {
  if (used[x]) return;
  used[x] = 1;
  for (int i = h[x]; i; i = nxt[i]) {
    if (i / 2 > now) continue;
    ok[i >> 1] = 1;
    dfs(to[i], now);
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &v[i]), fa[i] = i;
  for (int i = 1; i <= m; i++) scanf("%d%d%d", &e[i].x, &e[i].y, &e[i].c);
  std::sort(e + 1, e + m + 1, cmp);
  for (int i = 1; i <= m; i++) {
    int X = Find(e[i].x), Y = Find(e[i].y);
    ins(e[i].x, e[i].y);
    ins(e[i].y, e[i].x);
    if (X != Y) fa[X] = Y, v[Y] += v[X];
    if (v[Y] < e[i].c) del[i] = 1;
  }
  int ans = 0;
  for (int i = m; i >= 1; i--) {
    if (del[i] && !ok[i]) ans++;
    if (!del[i] && !ok[i]) dfs(e[i].x, i);
  }
  printf("%d\n", ans);
}
