#include <bits/stdc++.h>
using namespace std;
struct edge {
  int x, y, z;
  inline bool operator<(const edge t) const { return z < t.z; }
};
edge e[300000];
int f[300000], g[300000], h[300000];
int i, m, n, t, fx, fy;
inline int getfather(int x) {
  if (f[x] == x)
    return x;
  else
    return f[x] = getfather(f[x]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%d", &g[i]);
  for (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 (i = 1; i <= n; i++) f[i] = i;
  for (i = 1; i <= m; i++) {
    fx = getfather(e[i].x);
    fy = getfather(e[i].y);
    if (fx != fy) f[fx] = fy, g[fy] = g[fy] + g[fx], h[fy] = h[fy] + h[fx];
    h[fy]++;
    if (g[fy] >= e[i].z) h[fy] = 0;
  }
  for (i = 1; i <= n; i++)
    if (getfather(i) == i) t = t + h[i];
  printf("%d", t);
  return 0;
}
