#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<int,int> P;
#define Mod 1000000007

int par[101010];
int ranki[101010];
ll weigh[101010];
ll loop;
int info[101010][5];


void init(int n){
    for(int i=0;i<n;i++){
        par[i]=i;
        ranki[i]=0;
    }
}

int find(int x){
    if(par[x]==x) return x;
    else return par[x]=find(par[x]);
}
a
void unite(int x,int y){
    ll x0=x,y0=y;
    x=find(x);
    y=find(y);

    if(x==y) {
        info[loop][0]=0;
        info[loop][1]=x;
        info[loop][2]=weigh[x];
        info[loop][3]=y;
        info[loop][4]=weigh[y];
        return;
    }

    else {
    info[loop][0]=1;
    info[loop][1]=x;
    info[loop][2]=weigh[x];
    info[loop][3]=y;
    info[loop][4]=weigh[y];

    if(ranki[x]<ranki[y]){
        par[x]=y;
        weigh[y]=weigh[x]+weigh[y];
        weigh[x]=weigh[y];
    } else{
        par[y]=x;
        if(ranki[x]==ranki[y]) ranki[x]++;
        weigh[x]=weigh[x]+weigh[y];
        weigh[y]=weigh[x];
    }

    }

}


bool same(int x,int y){
    return find(x)==find(y);
}

int main(){
    ll i,j;

    ll n,m;

    cin>>n>>m;

    init(n+10);
    ll x[n];
    for(i=0;i<n;i++){
        cin>>x[i];
        weigh[i]=x[i];
    }


    vector < pair < ll, pair<ll,ll> > > e;
    ll a,b,y;

    for(i=0;i<m;i++){
        cin>>a>>b>>y;
        e.pb(make_pair(y,make_pair(a-1,b-1)));
    }
    sort(e.begin(),e.end());

    loop=0;
    for(i=0;i<m;i++){
        unite(e[i].se.fi,e[i].se.se);
        loop++;
    }

    loop--;
    ll ans=0;

    for(i=loop;i>=0;i--){
        if(e[i].fi > weigh[info[i][1]]){
            ans++;
            if(info[i][0]==1){
            weigh[info[i][1]]=info[i][2];
            weigh[info[i][3]]=info[i][4];
            }
        }
    }

    cout<<ans<<endl;
    return 0;

    


}