#include <bits/stdc++.h>
using std::sort;
using std::vector;
const int N = 1e5 + 5, M = 2e5 + 5;
int n, m, ans;
int dis[N], book[N];
long long a[N];
struct edge {
  int u, v, w;
} e[M];
int can[M], bk[M];
vector<edge> V[N];
inline int find(int x) { return dis[x] == x ? x : (dis[x] = find(dis[x])); }
inline void merge(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return;
  dis[x] = y;
  a[y] += a[x];
  return;
}
void dfs(int x, int w) {
  register int i;
  for (auto c : V[x])
    if (c.w <= w && !bk[c.u] && !book[c.v])
      bk[c.u] = 1, book[c.v] = 1, dfs(c.v, w);
  return;
}
signed main() {
  register int i;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) dis[i] = i, scanf("%lld", &a[i]);
  for (i = 1; i <= m; i++) scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
  sort(e + 1, e + m + 1, [](edge a, edge b) -> bool { return a.w < b.w; });
  for (i = 1; i <= m; i++) {
    V[e[i].u].push_back(edge{i, e[i].v, e[i].w});
    V[e[i].v].push_back(edge{i, e[i].u, e[i].w});
  }
  for (i = 1; i <= m; i++) {
    merge(e[i].u, e[i].v);
    if (a[find(e[i].u)] >= e[i].w) can[i] = 1;
  }
  for (i = m; i >= 1; i--)
    if (can[i]) book[e[i].u] = 1, bk[i] = 1, dfs(e[i].u, e[i].w);
  for (i = 1; i <= m; i++)
    if (bk[i]) ans++;
  printf("%d\n", m - ans);
  return 0;
}
