#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define trav(a,x) for(auto &a:x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

struct UF {
	vi e;
    vector<ll> sumv;
    vector<int> ans, nume;
    int tot;
    UF(int n, const vector<ll> &x) : e(n, -1), sumv(x), ans(n, 0), nume(n, 0), tot(0) {}
	bool same_set(int a, int b) { return find(a) == find(b); }
	int size(int x) { return -e[find(x)]; }
	int find(int x) { return e[x] < 0 ? x : e[x] = find(e[x]); }
	void join(int a, int b, ll y) {
		a = find(a), b = find(b);
		if(a==b) {
            ++nume[a];
            if(y<=sumv[a]) {
                ++tot;
                ++ans[a];
            }
            return;
        }
		if (e[a] > e[b]) swap(a, b);
		e[a] += e[b]; e[b] = a;
        nume[a] += nume[b];
        sumv[a] += sumv[b];
        ++nume[a];
        tot -= ans[a];
        tot -= ans[b];
        if(y<= sumv[a]) {
            ans[a] = nume[a];
        }
        else {
            ans[a] = ans[a]+ans[b];
        }
        tot += ans[a];
	}
};


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<ll> x(n);
    rep(i,0,n) cin >> x[i];
    vector<tuple<ll,int,int>> edges;
    rep(i,0,m) {
        int u, v;
        ll y;
        cin >> u >> v >> y;
        --u;
        --v;
        edges.emplace_back(y,u,v);
    }
    sort(all(edges));
    UF uf(n, x);
    for(const auto &e: edges) {
        int u, v;
        ll y;
        tie(y,u,v) = e;
        uf.join(u,v,y);
    }
    int ans = m-uf.tot;
    cout << ans << "\n";
}
