#include <bits/stdc++.h>
namespace my_std {
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>
inline T rnd(T l, T r) {
  return uniform_int_distribution<T>(l, r)(rng);
}
template <typename T>
inline bool chkmax(T &x, T y) {
  return x < y ? x = y, 1 : 0;
}
template <typename T>
inline bool chkmin(T &x, T y) {
  return x > y ? x = y, 1 : 0;
}
template <typename T>
inline void read(T &t) {
  t = 0;
  char f = 0, ch = getchar();
  double d = 0.1;
  while (ch > '9' || ch < '0') f |= (ch == '-'), ch = getchar();
  while (ch <= '9' && ch >= '0') t = t * 10 + ch - 48, ch = getchar();
  if (ch == '.') {
    ch = getchar();
    while (ch <= '9' && ch >= '0') t += d * (ch ^ 48), d *= 0.1, ch = getchar();
  }
  t = (f ? -t : t);
}
template <typename T, typename... Args>
inline void read(T &t, Args &...args) {
  read(t);
  read(args...);
}
char sr[1 << 21], z[20];
int C = -1, Z = 0;
inline void Ot() { fwrite(sr, 1, C + 1, stdout), C = -1; }
inline void print(register int x) {
  if (C > 1 << 20) Ot();
  if (x < 0) sr[++C] = '-', x = -x;
  while (z[++Z] = x % 10 + 48, x /= 10)
    ;
  while (sr[++C] = z[Z], --Z)
    ;
  sr[++C] = '\n';
}
}  // namespace my_std
using namespace my_std;
int n, m;
struct hh {
  int u, v, w;
} edge[102020];
inline bool cmp(const hh &x, const hh &y) { return x.w < y.w; }
int fa[102020], sum[102020];
int cnt[102020];
int getfa(int x) { return x == fa[x] ? x : fa[x] = getfa(fa[x]); }
int main() {
  read(n, m);
  for (int i = (1); i <= (n); i++) read(sum[fa[i] = i]);
  int x, y, z;
  for (int i = (1); i <= (m); i++) read(x, y, z), edge[i] = (hh){x, y, z};
  sort(edge + 1, edge + m + 1, cmp);
  int ans = 0;
  for (int i = (1); i <= (m); i++) {
    int u = edge[i].u, v = edge[i].v;
    u = getfa(u), v = getfa(v);
    if (u != v) fa[u] = v, sum[v] += sum[u], cnt[v] += cnt[u];
    ++cnt[v];
    if (sum[v] >= edge[i].w) ans += cnt[v], cnt[v] = 0;
  }
  cout << m - ans;
  return 0;
}
