#include <bits/stdc++.h>
using namespace std;
const long long NMAX = 1e6;
vector<long long> child, tree(NMAX), sum(NMAX), cnt(NMAX, 0);
long long root(long long i) {
  if (i == tree[i]) {
    for (long long j = (0); j < (child.size()); j++) tree[child[j]] = i;
    child.clear();
    return i;
  } else {
    child.push_back(i);
    return i = root(tree[i]);
  }
}
long long unit(long long x, long long y) {
  x = root(x);
  y = root(y);
  tree[max(x, y)] = min(x, y);
  sum[x] += sum[y];
  sum[y] = sum[x];
  cnt[min(x, y)] = cnt[max(x, y)] + 1;
}
bool isUnit(long long x, long long y) { return root(x) == root(y); }
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n);
  for (long long i = (0); i < (n); i++) cin >> a[i];
  vector<pair<long long, pair<long long, long long>>> edge(m);
  for (long long i = (0); i < (m); i++) {
    long long x, y, c;
    cin >> x >> y >> c;
    edge[i] = make_pair(c, pair<long long, long long>(x - 1, y - 1));
  }
  sort(edge.begin(), edge.end());
  for (long long i = (0); i < (n); i++) tree[i] = i, sum[i] = a[i];
  long long ans = m;
  vector<pair<long long, long long>> tmp;
  vector<long long> coS;
  for (long long i = (0); i < (m); i++) {
    long long x = edge[i].second.first, y = edge[i].second.second,
              co = edge[i].first;
    if (!isUnit(x, y)) {
      unit(x, y);
      if (sum[root(x)] >= co)
        ans -= cnt[root(x)], cnt[root(x)] = cnt[root(y)] = 0;
    } else
      tmp.push_back(pair<long long, long long>(x, y)), coS.push_back(co);
  }
  for (long long i = (0); i < (tmp.size()); i++)
    if (sum[root(tmp[i].first)] >= coS[i]) ans--;
  cout << ans << endl;
  return 0;
}
