#include <bits/stdc++.h>
using namespace std;
int n, m, cnt, ans, head[100005], f[100005], b[100005];
long long num[100005];
struct Edge {
  int next, to;
  long long dis;
} edge[100005 * 2];
struct E {
  int x, y;
  long long z;
} e[100005];
void addedge(int from, int to, long long dis) {
  edge[++cnt].next = head[from];
  edge[cnt].to = to;
  edge[++cnt].dis = dis;
  head[from] = cnt;
}
bool CMP(E x, E y) { return x.z < y.z; }
int find(int x) {
  if (f[x] != x) f[x] = find(f[x]);
  return f[x];
}
int main() {
  scanf("%d%d", &n, &m);
  for (register int i = 1; i <= n; ++i) scanf("%lld", &num[i]);
  for (register int i = 1, x, y; i <= m; ++i) {
    scanf("%d%d%lld", &e[i].x, &e[i].y, &e[i].z);
    addedge(e[i].x, e[i].y, e[i].z);
    addedge(e[i].y, e[i].x, e[i].z);
  }
  for (register int i = 1; i <= n; ++i) f[i] = i;
  sort(e + 1, e + m + 1, CMP);
  for (register int i = 1; i <= m; ++i) {
    int fx = find(e[i].x), fy = find(e[i].y);
    if (fx == fy) {
      if (num[fx] < e[i].z) ans++, b[fx]++;
    } else {
      f[fx] = fy, num[fy] += num[fx];
      b[fy] += b[fx];
      if (num[fy] >= e[i].z) {
        ans -= b[fy];
        b[fy] = 0;
      } else {
        b[fy]++;
        ans++;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
