#include <bits/stdc++.h>
using namespace std;
const int N = 300 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;
const int MAGIC = 400;
struct edge {
  int u, v;
  bool f;
  long long w;
};
struct dsu {
  int n;
  vector<int> P, p, W, w, L, U;
  vector<long long> wgt, Wgt;
  dsu() = default;
  dsu(int n, long long* _wgt) : n(n) {
    p.resize(n);
    iota(p.begin(), p.end(), 0);
    w.assign(n, 1);
    wgt = vector<long long>(_wgt, _wgt + n);
    L.reserve(n);
    P = p;
    W = w;
    Wgt = wgt;
    U.assign(n, 0);
  }
  inline void mark(int i) {
    if (!U[i]) {
      U[i] = 1;
      L.emplace_back(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 (const auto& i : L) {
      U[i] = 0;
      p[i] = P[i];
      w[i] = W[i];
      wgt[i] = Wgt[i];
    }
    L.clear();
  }
  void fix() {
    for (const auto& i : L) {
      U[i] = 0;
      P[i] = p[i];
      W[i] = w[i];
      Wgt[i] = wgt[i];
    }
    L.clear();
  }
};
int n, m;
long long X[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 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);
      dsu D(n, X);
      for (int i = 0; i < m; ++i)
        if (i < l || (i > r && E[i].f)) D.join(E[i].u, E[i].v);
      D.fix();
      for (int i = r; i >= l; --i) {
        for (int j = l; j <= i; ++j) D.join(E[j].u, E[j].v);
        if (D.getw(E[i].u) < E[i].w) E[i].f = 0;
        D.rollback();
        if (E[i].f) {
          D.join(E[i].u, E[i].v);
          D.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;
}
