#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

struct UnionFind {
  vector< int > data;

  UnionFind(int sz) {
    data.assign(sz, -1);
  }

  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k) {
    return (-data[find(k)]);
  }
};




int main(){

  int n,m;
  cin >> n >> m;
  ll x[n];
  rep(i,n) cin >> x[i];
  ll a[m],b[m],y[m];
  rep(i,m){
    cin >> a[i] >> b[i] >> y[i];
    a[i]--;b[i]--;
  }
  bool need[m];
  rep(i,m) need[i]=true;
  bool update = true;
  while(update){
    update=false;
    UnionFind uf(n);
    rep(i,m){
      if(need[i]) uf.unite(a[i],b[i]);        
    }
    ll weight[n];
    rep(i,n) weight[i]=0;
    rep(i,n){
      weight[uf.find(i)]+=x[i];
    }
    rep(i,m){
      if(need[i]){
	if(weight[uf.find(a[i])]<y[i]){
	  ka++;
	  need[i]=false;
	  update=true;
	}
      }
    }
  }
  int ans=0;
  rep(i,m) if(!need[i]) ans++;
  cout << ans << endl;
  return 0;

}
