#include<iostream>
#include<algorithm>
#include<vector>
typedef long long ll;

using namespace std;
#define N 100010
ll n,m,x[N];
class UnionFind{
  public:
  ll p[N],es[N],as[N],vs[N];
  void init(){
    for(int i=0;i<N;i++){
      p[i]=i;es[i]=as[i]=0;
      vs[i]=x[i];
    }
  }
  ll Par(ll x){
    ll y=x,z;
    while(y!=p[y])y=p[y];
    while(x!=y)z=p[x],p[x]=y,x=z;
    return x;
  }
  void Unite(ll a,ll b,ll key){
    a=Par(a); b=Par(b);
    if(a==b){
      es[a]++;
      if(vs[a]>=key)as[a]=es[a];
    }
    else{
      p[b]=a;
      es[a]+=es[b]+1;
      as[a]+=as[b];
      vs[a]+=vs[b];
      if(vs[a]>=key)as[a]=es[a];
    }
  }
  ll Solve(){
    ll x=Par(0);
    return as[x];
  }
};UnionFind uf;
ll a[N],b[N];
typedef pair<ll,ll> P;
P d[N];
int main(){
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>x[i];
    for(int i=0;i<m;i++){
      cin>>a[i]>>b[i];a[i]--,b[i]--;
      ll cost;cin>>cost;
      d[i]=make_pair(cost,i);
    }
    sort(d,d+m);
    uf.init();
    for(int i=0;i<m;i++){
      ll j=d[i].second;
      ll cost=d[i].first;
      uf.Unite(a[j],b[j],cost);
    }
    cout<<m-uf.Solve()<<endl;
    return 0;
}
