#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e18+7;

struct UnionFind{
    ll n;
    vector<ll> sum, par, l, h;

    UnionFind(ll n, vector<ll>& sum) : n(n), sum(sum), par(n, -1), l(n, 0), h(n, 0){}

    bool Unite(ll x, ll y, ll cost){
        x = Find(x);
        y = Find(y);

        if(x == y){
            ++(sum[x] >= cost ? l[x] : h[x]);
            return false;
        }
        if(par[x] > par[y])
            swap(x, y);

        par[x] += par[y];
        par[y] = x;
        l[x] += l[y];
        h[x] += h[y];
        sum[x] += sum[y];
        ++h[x];
        if(sum[x] >= cost){
            l[x] += h[x];
            h[x] = 0;
        }
        return true;
    }

    ll Find(ll x){
        return par[x] < 0 ? x : Find(par[x]);
    }

    ll Sum(){
        ll s = 0;
        for(ll i = 0; i < n; ++i)
            if(par[i] < 0)
                s += h[i];
        return s;
    }

};

signed main(){
    ll n, m;
    cin >> n >> m;
    vector<ll> v(n), a(m), b(m), c(m);
    for(auto& x : v)
        cin >> x;
    vector<pair<ll, pair<ll,ll>>> p;
    for(ll i = 0; i < m; ++i){
        cin >> a[i] >> b[i] >> c[i];
        p.emplace_back(c[i], make_pair(--a[i], --b[i]));
    }

    sort(p.begin(), p.end());

    UnionFind u(n, v);
    for(auto& q : p){
        u.Unite(q.second.first, q.second.second, q.first);
    }
    cout << u.Sum() << endl;

}
