#include<bits/stdc++.h>

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N,M;
vector<pair<ll,pll>> jv;
ll ct[101010];
ll i, j,ans;
ll mk[101010];

ll gc[101010],ghn[101010], ghnd[101010];
ll gnxt[101010];
ll ggt(ll a){
    ll aa = a;
    while(gnxt[aa]!=aa){
        aa = gnxt[aa];
    }
    return gnxt[a] = aa;
}
int main(){
    scanf("%lld%lld", &N,&M);
    fornum(i,0,N){
        ll x;
        scanf("%lld", &x);
        gnxt[i+1] = i + 1;
        gc[i + 1] = x;
    }
    fornum(i, 0,M){
        ll a, b,c;
        scanf("%lld%lld%lld", &a, &b,&c);
        jv.push_back(mp(c,mp(a,b)));
    }
    sort(jv.begin(), jv.end());
    fornum(i,0,M){
        auto ja = jv[i];
        auto jp = ja.second;
        ll a = ggt(jp.first);
        ll b = ggt(jp.second);
        if(a!=b){
            gc[a] += gc[b];
            ghn[a] += ghn[b];
            ghnd[a] += ghnd[b];
            gnxt[b] = a;
        }
        ghnd[a]++;
        if(jv[i].first<=gc[a]){
            ghn[a] = ghnd[a];
        }
    }


    fornum(i,0,N){
        ll a = ggt(i + 1);
        if(mk[a]==0){
            mk[a] = 1;
            ans += ghnd[a] - ghn[a];
        }   
    }
    printf("%lld", ans);
    return 0;
}