#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long long inf = 1e18;
const int mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<int> gra[100005];
int dsu[100005];
int wei[100005];
int pend[100005];
vector<pair<int, pair<int, int>>> edges;
int fpar(int i) { return (dsu[i] < 0) ? i : dsu[i] = fpar(dsu[i]); }
void merge(int i, int j) {
  if ((i = fpar(i)) != (j = fpar(j))) {
    if (dsu[i] > dsu[j]) swap(i, j);
    pend[i] += pend[j];
    wei[i] += wei[j];
    dsu[i] += dsu[j];
    dsu[j] = i;
  }
}
void solve() {
  int n, m, u, v, w;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) dsu[i] = -1;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    cin >> wei[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> u >> v >> w;
    edges.push_back({w, {u, v}});
  }
  sort(edges.begin(), edges.end());
  for (int i = 0; i < m; i++) {
    merge(edges[i].second.first, edges[i].second.second);
    int comp = fpar(edges[i].second.first);
    pend[comp]++;
    if (wei[comp] >= edges[i].first) {
      ans += pend[comp];
      pend[comp] = 0;
    }
  }
  cout << m - ans << '\n';
}
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  srand(chrono::steady_clock::now().time_since_epoch().count());
  auto clk = clock();
  int t = 1;
  while (t--) solve();
  return 0;
}
