#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long p = 0;
  long long f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    p = p * 10 + (ch - '0');
    ch = getchar();
  }
  return p * f;
}
struct node {
  long long x, y, d;
  node() {}
  node(long long _x, long long _y, long long _d) {
    x = _x;
    y = _y;
    d = _d;
  }
} edge[100010], a[100010];
long long len;
bool cmp(const node &x, const node &y) { return x.d < y.d; }
long long val[100010], fa[100010], siz[100010];
long long ffind(long long x) { return (fa[x] == x) ? fa[x] : ffind(fa[x]); }
int main() {
  long long n = read(), m = read();
  for (long long i = 1; i <= n; i++) val[i] = read(), fa[i] = i, siz[i] = 1;
  for (long long i = 1; i <= m; i++) {
    a[i].x = read();
    a[i].y = read();
    a[i].d = read();
  }
  len = 0;
  sort(a + 1, a + m + 1, cmp);
  for (long long i = 1; i <= m; i++) {
    long long x = ffind(a[i].x);
    long long y = ffind(a[i].y);
    if (x != y) {
      if (siz[x] < siz[y]) swap(x, y);
      len++;
      edge[len] = node(x, y, a[i].d);
      val[x] += val[y];
      siz[x] += siz[y];
      fa[y] = x;
    }
  }
  for (long long i = len; i >= 1; i--) {
    long long x = edge[i].x;
    long long y = edge[i].y;
    if (edge[i].d > val[x]) {
      val[x] -= val[y];
      fa[y] = y;
    }
  }
  long long s = 0;
  for (long long i = 1; i <= m; i++) {
    long long x = ffind(a[i].x);
    long long y = ffind(a[i].y);
    if (x == y && val[x] >= a[i].d) s++;
  }
  return printf("%lld\n", m - s), 0;
}
