#include <bits/stdc++.h>
using namespace std;
int const maxn = 1e5 + 5, K = 600;
int x[maxn], used[maxn], cur, oks[maxn], tmp, timer, was[maxn];
set<int> g[maxn];
multiset<int> G[maxn];
long long sum[maxn], f;
void dfs1(int v) {
  oks[v] = tmp;
  f += sum[v];
  for (auto u : G[v]) {
    if (oks[u] != tmp) dfs1(u);
  }
}
void dfs(int v) {
  was[v] = timer, used[v] = cur, sum[cur] += (long long)x[v];
  for (auto u : g[v])
    if (was[u] != timer) dfs(u);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, u, v, c, ans = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> x[i];
  vector<vector<int> > go;
  for (int i = 1; i <= m; ++i) {
    cin >> u >> v >> c;
    g[u].insert(v);
    g[v].insert(u);
    go.push_back({c, u, v});
  }
  sort(go.rbegin(), go.rend());
  for (int i = 0; i < m; i += K) {
    int R = min(m, i + K);
    for (int j = i; j < R; ++j) {
      u = go[j][1], v = go[j][2];
      g[u].erase(v), g[v].erase(u);
    }
    cur = 0, timer++;
    for (int j = 1; j <= n; ++j) {
      if (was[j] != timer) {
        cur++;
        sum[cur] = 0;
        dfs(j);
      }
    }
    for (int j = i; j < R; ++j) {
      u = go[j][1], v = go[j][2];
      if (used[u] != used[v])
        G[used[u]].insert(used[v]), G[used[v]].insert(used[u]);
    }
    for (int j = i; j < R; ++j) {
      c = go[j][0], u = go[j][1], v = go[j][2];
      tmp++, f = 0;
      dfs1(used[u]);
      if (f < c) {
        ans++;
        u = used[u], v = used[v];
        if (u == v) continue;
        G[u].erase(G[u].find(v));
        G[v].erase(G[v].find(u));
      } else
        g[u].insert(v), g[v].insert(u);
    }
    for (int j = i; j < R; ++j) {
      u = used[go[j][1]], v = used[go[j][2]];
      G[u] = {}, G[v] = {};
    }
  }
  cout << ans << '\n';
  return 0;
}
