
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <queue>
#define PIE 3.14159265358979
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;
typedef long long ll;


int N,M;
vector<pair<int,ll> > G[100005];
vector<ll> V;
vector<pair<ll,pair<int,int> > > E;


class union_find{
    int n;
    vector<int> par;
    vector<int> rank;
public:
    union_find(int n){  //初期化
        this->n=n;
        par = vector<int>(n,0);
        rep(i,n){par[i]=i;}
        rank = vector<int>(n,0);
    }
    int find(int x){    //親
        if(par[x]==x){
            return x;
        }else{
            par[x]=find(par[x]);
            return par[x];
        }
    }
    void unite(int x,int y){    //結合
        x=find(x);
        y=find(y);
        if(x==y){return;}
        if(rank[x]<rank[y]){
            par[x]=y;
        }else{
            par[y]=x;
            if(rank[x]==rank[y])rank[x]++;
        }
    }
    bool same(int x,int y){     //同じグループか判定
        return find(x)==find(y);
    }
};



int main(){
    cin>>N>>M;
    union_find uf(N);
    vector<ll> vsum,esum;
    vsum.resize(N,0),esum.resize(N,0);
    E.resize(M);
    rep(i,N){
        cin>>vsum[i];
    }
    rep(i,M){
        int a,b;ll y;
        cin>>a>>b>>y;
        a--,b--;
        E[i]=make_pair(y,make_pair(a,b));
    }
    sort(E.begin(),E.end());
    int ans = M;
    for(auto e: E){
        ll cost = e.first;
        int v1 = e.second.first,v2 = e.second.second;
        v1=uf.find(v1),v2=uf.find(v2);
        int par = uf.find(v1);
        if(v1!=v2){
            uf.unite(v1,v2);
            par=uf.find(v1);
            vsum[par]=vsum[v1]+vsum[v2];
            esum[par]=esum[v1]+esum[v2]+1;
        }else{
            esum[par]++;
        }
        if(vsum[par]>=cost){
            ans -= esum[par];
            esum[par]=0;
        }
    }
    cout<<ans<<endl;
    
}

