#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ull = unsigned long long;
using ld = long double;
template <typename T>
void _(const char* s, T h) {
  cerr << s << " = " << h << "\n";
}
template <typename T, typename... Ts>
void _(const char* s, T h, Ts... t) {
  int b = 0;
  while (((b += *s == '(') -= *s == ')') != 0 || *s != ',') cerr << *s++;
  cerr << " = " << h << ",";
  _(s + 1, t...);
}
struct init {
  init() {
    cin.tie(0);
    iostream::sync_with_stdio(0);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(5);
  }
  ~init() {}
} init;
template <typename T, typename U>
void upx(T& x, U y) {
  if (x < y) x = y;
}
template <typename T, typename U>
void upn(T& x, U y) {
  if (x > y) x = y;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll D = 4, dx[] = {+1, 0, -1, 0}, dy[] = {0, +1, 0, -1};
const ll N = 1e5 + 5;
struct edge {
  ll x, y, w;
} es[N];
vector<ll> g[N];
ll go(ll v, ll i) { return v ^ es[i].x ^ es[i].y; }
ll p[N], tot[N], a[N], ok[N], u[N];
ll get(ll x) { return x == p[x] ? x : (p[x] = get(p[x])); }
void join(ll x, ll y) {
  x = get(x);
  y = get(y);
  if (x ^ y) {
    p[y] = x;
    tot[x] += tot[y];
  }
}
void dfs(ll v, ll x) {
  if (u[v]) return;
  u[v] = 1;
  for (ll i : g[v]) {
    ll to = go(v, i);
    if (!u[to]) dfs(to, x);
    if (es[i].w <= x) ok[i] = 1;
  }
}
int32_t main() {
  ll n, m;
  cin >> n >> m;
  for (ll i = 1; i <= n; ++i) {
    cin >> a[i];
    p[i] = i;
    tot[i] = a[i];
  }
  for (ll i = 0; i < (m); ++i) cin >> es[i].x >> es[i].y >> es[i].w;
  sort(es, es + m, [](const edge& p1, const edge& p2) { return p1.w < p2.w; });
  for (ll i = 0; i < (m); ++i) {
    g[es[i].x].emplace_back(i);
    g[es[i].y].emplace_back(i);
  }
  for (ll i = 0; i < (m); ++i) {
    join(es[i].x, es[i].y);
    ok[i] = tot[get(es[i].x)] >= es[i].w;
  }
  ll ans = 0;
  for (ll i = m - 1; i >= 0; --i) {
    if (ok[i])
      dfs(es[i].x, es[i].w);
    else
      ans++;
  }
  cout << ans << '\n';
  return 0;
}
