#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const long long N = 100005;
struct node {
  long long u, v, w;
} E[N];
long long fa[N], val[N], size[N];
long long find(long long x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') f = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    x = (x << 1) + (x << 3) + ch - '0';
  return x * f;
}
bool cmp(node a, node b) { return a.w < b.w; }
signed main() {
  long long n = read(), m = read();
  for (long long i = 1; i <= n; i++)
    val[i] = read(), fa[i] = i, size[i] = val[i];
  for (long long i = 1; i <= m; i++) {
    E[i].u = read(), E[i].v = read(), E[i].w = read();
    if (E[i].u > E[i].v) swap(E[i].u, E[i].v);
  }
  sort(E + 1, E + m + 1, cmp);
  long long ans;
  for (long long i = 1; i <= m; i++) {
    long long fx = find(E[i].u), fy = find(E[i].v);
    if (fx == fy) {
      if (E[i].w > size[fx]) continue;
    } else {
      fa[fy] = fx;
      size[fx] += size[fy];
      if (E[i].w > size[fx]) continue;
    }
    ans = i;
  }
  printf("%d\n", m - ans);
  return 0;
}
