#include <bits/stdc++.h>
using namespace std;
int a[100005], f[100005], rk[100005], g[100005], n, m, ans;
int A[100005], B[100005], C[100005], cut[100005], tot;
struct edge {
  int x, y, z;
  int operator<(const edge &b) const { return z < b.z; }
} e[100005];
int get(int u) {
  for (; f[u] != u; u = f[u])
    ;
  return u;
}
void Union(int u, int v) {
  if (rk[u] < rk[v]) swap(u, v);
  ++tot;
  A[tot] = u;
  B[tot] = v;
  C[tot] = rk[u] == rk[v];
  f[v] = u;
  rk[u] += C[tot];
  g[u] += g[v];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= m; i++) scanf("%d%d%d", &e[i].x, &e[i].y, &e[i].z);
  sort(e + 1, e + m + 1);
  for (int i = 1; i <= n; i++) f[i] = i, g[i] = a[i], rk[i] = 0;
  for (int i = 1; i <= m; i++) {
    int u = get(e[i].x), v = get(e[i].y);
    if (u == v)
      cut[i] = 0;
    else
      cut[i] = 1, Union(u, v);
  }
  for (int i = m; i; i--)
    if (!cut[i]) {
      ans += g[get(e[i].x)] < e[i].z;
    } else {
      int u = A[tot], v = B[tot], w = C[tot];
      tot--;
      if (g[u] >= e[i].z) continue;
      f[v] = v;
      rk[u] -= w;
      g[u] -= g[v];
      ans++;
    }
  printf("%d\n", ans);
}
