#include <bits/stdc++.h>
using namespace std;
int n, m, val[100005], par[100005], cnt[100005];
int u[100005], v[100005], c[100005];
int in[100005];
bool tak[100005];
int get_par(int i) {
  if (par[i] == i) return i;
  return par[i] = get_par(par[i]);
}
bool cmp(int i, int j) { return c[i] < c[j]; }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> val[i], par[i] = i;
  for (int i = 1; i <= m; i++) cin >> u[i] >> v[i] >> c[i], in[i] = i;
  sort(in + 1, in + m + 1, cmp);
  int ans = 0;
  for (int i1 = 1; i1 <= m; i1++) {
    int i = in[i1];
    int x = get_par(u[i]);
    int y = get_par(v[i]);
    if (x != y) val[y] += val[x], cnt[y] = cnt[x] + cnt[y], par[x] = y;
    cnt[y]++;
    if (val[y] >= c[i]) tak[i] = 1, ans += cnt[y], cnt[y] = 0;
  }
  cout << m - ans << '\n';
  return 0;
}
