#include <bits/stdc++.h>
using namespace std;
pair<long long, pair<long long, long long> > mk_P(long long a, long long b,
                                                  long long c) {
  return pair<long long, pair<long long, long long> >(
      a, pair<long long, long long>(b, c));
}
struct uftree {
 private:
  vector<long long> par, val, rnk;

 public:
  uftree(long long n) {
    par.resize(n + 5);
    val.resize(n + 5);
    rnk.resize(n + 5);
    for (long long i = 0; i <= n; i++) {
      par[i] = i;
      val[i] = 0;
      rnk[i] = 0;
    }
  }
  long long find(long long pos) {
    if (par[pos] == pos)
      return pos;
    else
      return par[pos] = find(par[pos]);
  }
  void set_val(long long pos, long long x) { val[pos] = x; }
  bool same(long long a, long long b) { return find(a) == find(b); }
  long long sum(long long pos) { return val[find(pos)]; }
  void unite(long long a, long long b) {
    a = find(a);
    b = find(b);
    if (same(a, b)) return;
    if (rnk[a] < rnk[b]) {
      par[a] = b;
      val[b] += val[a];
    } else {
      par[b] = a;
      val[a] += val[b];
      if (rnk[a] == rnk[b]) rnk[a]++;
    }
  }
};
bool kans[100005], ans[100005];
vector<pair<long long, pair<long long, long long> > > node[100005];
void dfs(long long pos, long long border) {
  for (long long i = 0; i < node[pos].size(); i++) {
    long long to = node[pos][i].first, cos = node[pos][i].second.first;
    long long idx = node[pos][i].second.second;
    if (!ans[idx] && cos <= border) {
      ans[idx] = true;
      dfs(to, border);
    }
  }
}
signed main() {
  long long n, m;
  cin >> n >> m;
  uftree uf(n + 5);
  for (long long i = 1; i <= n; i++) {
    long long a;
    cin >> a;
    uf.set_val(i, a);
  }
  vector<pair<long long, pair<long long, long long> > > vec;
  for (long long i = 0; i < m; i++) {
    kans[i] = false;
    long long a, b, c;
    cin >> a >> b >> c;
    vec.push_back(mk_P(c, a, b));
    node[a].push_back(mk_P(b, c, i));
    node[b].push_back(mk_P(a, c, i));
  }
  sort(vec.begin(), vec.end());
  for (long long i = 0; i < m; i++) {
    ans[i] = false;
    long long s = vec[i].second.first, t = vec[i].second.second;
    long long cos = vec[i].first;
    uf.unite(s, t);
    if (uf.sum(s) >= cos) {
      kans[i] = true;
    }
  }
  for (long long i = m - 1; i >= 0; i--) {
    if (kans[i] && !ans[i]) {
      dfs(vec[i].second.first, vec[i].first);
    }
  }
  long long cnt = 0;
  for (long long i = 0; i < m; i++) {
    if (!ans[i]) {
      cnt++;
    }
  }
  cout << cnt << endl;
}
