//In The Name of Beauty
//...So here I go is my shot
//Feet fail me not 'cause maybe the only opportunity that I got...
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define IB std::ios::sync_with_stdio(0);
#define pb(x) push_back(x);
#define mp(x,y) make_pair(x,y)
#define pll pair<ll,ll>
#define F first
#define S second
ll const MAXN = 1e5 + 8;
ll const INF  = 1e12 + 8;
ll const delta = 1000000007;
ll a[MAXN];
ll par[MAXN];
ll sz[MAXN];
ll sum[MAXN];
ll q[MAXN];
ll getpar(ll v)
{
    if(par[v] == v)return v;
    return (par[v] = getpar(par[v]));
}
void mergee(ll v,ll u)
{
    v = getpar(v);
    u = getpar(u);
    if(v == u)return;
    if(sz[u] > sz[v])swap(v,u);
    sz[v] += sz[u];
    par[u] = v;
    sum[v] += sum[u];
    q[v] += q[u];
}
int main()
{
    IB;
    cin.tie(0);
    cout.tie(0);
    ll n , m;
    cin >> n >> m;
    for(ll i = 1;i <= n;i++)
    {
        cin >> a[i];
        sum[i] = a[i];
        par[i] = i;
        sz[i] = 1;
    }
    ll temp = 0;
    ll f , s , w;
    vector<pair<ll,pll> > edges;
    for(ll i = 0;i < m;i++)
    {
        cin >> f >> s >> w;
        edges.pb(mp(w,mp(f,s)));
    }
    sort(edges.begin(),edges.end());
    for(ll i = 0;i < m;i++)
    {
        ll v = edges[i].S.F;
        ll u = edges[i].S.S;
        w = edges[i].F;
        mergee(v,u);
        ll x = getpar(v);
        if(sum[x] >= w)
        {
            temp += (q[x] + 1);
            q[x] = 0;
        }
        else
        {
            q[x]++;
        }
    }
    cout << m - temp;
    return 0;
}
//Written by M_H_H_7
