#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = 100 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;
const int MAGIC = 370;
struct edge {
  int u, v;
  bool f;
  long long w;
};
int n, m, nn;
int p[N], P[N], w[N], W[N], U[N], L[N];
long long X[N], wgt[N], Wgt[N];
edge E[N];
bool read() {
  if (!(cin >> n >> m)) return false;
  for (int i = 0; i < n; ++i) cin >> X[i];
  for (int i = 0; i < m; ++i) {
    cin >> E[i].u >> E[i].v >> E[i].w;
    --E[i].u, --E[i].v;
    E[i].f = 1;
  }
  return true;
}
void init_dsu() {
  iota(p, p + n, 0);
  fill(w, w + n, 1);
  fill(U, U + n, 0);
  nn = 0;
  for (int i = 0; i < n; ++i) {
    wgt[i] = Wgt[i] = X[i];
    P[i] = p[i];
    W[i] = w[i];
  }
}
inline void mark(int i) {
  if (!U[i]) {
    U[i] = 1;
    L[nn++] = i;
  }
}
int getp(int v) {
  if (p[v] == v) return p[v];
  mark(v);
  return p[v] = getp(p[v]);
}
int getw(int v) { return wgt[getp(v)]; }
void join(int u, int v) {
  if ((u = getp(u)) == (v = getp(v))) return;
  if (w[u] < w[v]) swap(u, v);
  p[v] = u;
  w[u] += w[u] == w[v];
  wgt[u] += wgt[v];
  mark(u);
  mark(v);
}
void rollback() {
  for (int j = 0; j < nn; ++j) {
    auto i = L[j];
    U[i] = 0;
    p[i] = P[i];
    w[i] = W[i];
    wgt[i] = Wgt[i];
  }
  nn = 0;
}
void fix() {
  for (int j = 0; j < nn; ++j) {
    auto i = L[j];
    U[i] = 0;
    P[i] = p[i];
    W[i] = w[i];
    Wgt[i] = wgt[i];
  }
  nn = 0;
}
void solve() {
  sort(E, E + m, [](const edge& e1, const edge& e2) { return e1.w < e2.w; });
  for (int t = m - 1; t >= 0; --t)
    if (t % MAGIC == 0) {
      auto l = t;
      auto r = min(m - 1, t + MAGIC - 1);
      init_dsu();
      for (int i = 0; i < m; ++i)
        if (i < l || (i > r && E[i].f)) join(E[i].u, E[i].v);
      fix();
      for (int i = r; i >= l; --i) {
        for (int j = l; j <= i; ++j) join(E[j].u, E[j].v);
        if (getw(E[i].u) < E[i].w) E[i].f = 0;
        rollback();
        if (E[i].f) {
          join(E[i].u, E[i].v);
          fix();
        }
      }
    }
  auto ans = 0;
  for (int i = 0; i < m; ++i)
    if (!E[i].f) ++ans;
  cout << ans << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  while (read()) solve();
  return 0;
}
