// Brijesh Panara (201601074)
// DAIICT (India)
#include <bits/stdc++.h>
#include <time.h>
using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define minQueue priority_queue<ll,vector<ll>,greater<ll> > 
#define maxQueue priority_queue<ll,vector<ll>,less<ll> > 

#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define RFOR(i,a,b) for(ll i=a;i>b;i--)
#define FILL(a,b) memset((a),(b),sizeof((a)))

#define deb1(x) cout<<#x<<" : "<<x<<endl;
#define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;

#define MOD 1000000007
#define NAX 200005
#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN

void FAST()
{
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    //srand(time(NULL));
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);    

}

ll a[NAX];
bool flag[NAX];
vector<ll> adj[NAX];
map<pair<ll,ll>,ll> pos;
map<pair<ll,ll>,ll> weight;
map<pair<ll,ll>,bool> visited;

struct dsu
{
    ll n,components;
    vector<ll> id,sz;

    dsu(ll n):
    n(n),id(n),sz(n){}

    void init()
    {
        FOR(i,0,n)
        id[i]=i,sz[i]=a[i];
        components=n;
    }

    ll root(ll x)
    {
        while(x!=id[x])
        {
            id[x]=id[id[x]];
            x=id[x];
        }
        return x;
    }

    ll findSize(ll x)
    {
        while(x!=id[x])
        {
            id[x]=id[id[x]];
            x=id[x];
        }
        return sz[x];
    }

    void combine(ll u,ll v)
    {
        ll rt1 = root(u);
        ll rt2 = root(v);

        if(rt1==rt2)
        return;

        if(sz[rt1]>sz[rt2])
        swap(rt1,rt2);

        components--;
        id[rt1] = id[rt2];
        sz[rt2] += sz[rt1];
        sz[rt1] = 0;
    }
};

void dfs(ll ver,ll w)
{
    FOR(i,0,adj[ver].size())
    {
        ll adjver = adj[ver][i];
        if(weight[mp(ver,adjver)]<=w && visited[mp(ver,adjver)]==false)
        {
            visited[mp(ver,adjver)]=true;
            visited[mp(adjver,ver)]=true;
            flag[pos[mp(ver,adjver)]]=true;
            dfs(adjver,w);
        }
    }
}

int main()
{
    FAST();

    ll n,m;
    cin>>n>>m;

    FOR(i,0,n)
    cin>>a[i];

    pair<ll,pair<ll,ll> > edges[m];
    FOR(i,0,m)
    {
        ll u,v,w;
        cin>>u>>v>>w;
        u--;v--;
        edges[i]=mp(w,mp(u,v));
    }
    sort(edges,edges+m);

    FOR(i,0,m)
    {
        ll u = edges[i].ss.ff;
        ll v = edges[i].ss.ss;
        ll w = edges[i].ff;
        adj[u].pb(v);
        adj[v].pb(u);
        pos[mp(u,v)]=i;
        pos[mp(v,u)]=i;
        weight[mp(u,v)]=w;
        weight[mp(v,u)]=w;
    }

    dsu d(n);
    d.init();

    FOR(i,0,m)
    {
        ll u = edges[i].ss.ff;
        ll v = edges[i].ss.ss;
        ll w = edges[i].ff;

        d.combine(u,v);

        ll sz = d.findSize(u);
        if(sz>=w)
        flag[i]=true;

        //deb3(i,w,sz);
        //deb1(flag[i]);
    }

    for(ll i=m-1;i>=0;i--)
    {
        if(flag[i]==true)
        {
            ll u = edges[i].ss.ff;
            ll v = edges[i].ss.ss;
            ll w = edges[i].ff;

            dfs(u,w);
        }
    }

    ll cnt = 0;
    FOR(i,0,m)
    if(flag[i]==false)
    cnt++;
    
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 63232