#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

#define FOR(i,a) for (int i=0;i<(a);++i)
#define FORD(i,a) for (int i=(a)-1;i>=0;i--)
#define FORT(i,a,b) for (int i=(a);i<=(b);++i)
#define FORTD(i,b,a) for (int i=(b);i>=(a);--i)
#define trav(i,v) for (auto i : v)
#define fr first
#define sc second

const int N=1e5+6;
struct node{
    int par,ed,mxed;
    ll sum,mx;
} dsu[N];
int x[N];
void make_node(int i,int k){
    dsu[i].par=i;
    dsu[i].mx=0;
    dsu[i].sum=k;
    dsu[i].ed=0;
    dsu[i].mxed=0;
}

int get(int p){
    if (dsu[p].par==p)return p;
    return dsu[p].par=get(dsu[p].par);
}

void unite(int a,int b,ll len){
    a=get(a);
    b=get(b);
    if (a!=b){
        dsu[a].mxed+=dsu[b].mxed;
        dsu[a].ed+=dsu[b].ed+1;
        dsu[a].sum+=dsu[b].sum;
        dsu[a].mx=max(len,max(dsu[a].mx,dsu[b].mx));
        dsu[b].par=a;
    }
    else{
        dsu[a].mx=max(dsu[a].mx,len);
        dsu[a].ed++;
    }
    if (dsu[a].sum>=dsu[a].mx)dsu[a].mxed=dsu[a].ed;
}
int main(){
    ios_base::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    FOR(i,n){
        cin>>x[i];
        make_node(i+1,x[i]);
    }
    vector<pair<int,pair<int,int> > > v;
    FOR(i,m){
        int l,a,b;
        cin>>a>>b>>l;
        v.push_back({l,{a,b}});
    }
    sort(v.begin(),v.end());
    int ans=0;
    FOR(i,m){
        unite(v[i].sc.fr,v[i].sc.sc,v[i].fr);
        //cout<<v[i].sc.fr<<" "<<v[i].sc.sc<<" "<<v[i].fr<<" "<<qan<<endl;
    }
    cout<<m-dsu[get(1)].mxed<<endl;
    return 0;
}
