#include <bits/stdc++.h>

using namespace std;

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;

struct disjoint_sets{
	
	vector<ll> sum;
	vector<int> pi, sz, bad;
	
	disjoint_sets(int n, vector<ll> vals) : sum(n), pi(n), sz(n), bad(n){
		for(int i = 0; i < n; i++){
			pi[i] = i;
			sz[i] = 1;
			sum[i] = vals[i];
		}
	}
	
	int root(int x){
		return x == pi[x] ? x : root(pi[x]);
	}
	
	bool merge(int a, int b){
		a = root(a);
		b = root(b);
		
		if(a == b)
			return false;
		
		if(sz[a] > sz[b])
			swap(a, b);
		
		bad[b] += bad[a];
		sum[b] += sum[a];
		sz[b] += sz[a];
		pi[a] = b;
		return true;
	}
	
};

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n, m;
	cin >> n >> m;
	
	vector<ll> x(n);
	
	for(int i = 0; i < n; i++)
		cin >> x[i];
	
	disjoint_sets ds(n, x);

	vector<pair<ll, pii>> edges(m);
	for(int i = 0; i < m; i++){
		int a, b;
		ll c;
		cin >> a >> b >> c;
		a--, b--;
		edges[i] = {c, {a, b}};
	}
	
	sort(edges.begin(), edges.end());
	
	for(auto &e : edges){
		int a = e.second.first;
		int b = e.second.second;
		ll w = e.first;
		
		if(ds.merge(a, b)){
			int r = ds.root(a);
			
			if(ds.sum[r] >= w)
				ds.bad[r] = 0;
			else
				ds.bad[r]++;
		}
		else{
			int r = ds.root(a);
			if(ds.sum[r] < w)
				ds.bad[r]++;
		}
	}
	
	int ans = 0;
	set<int> R;
	for(int i = 0; i < n; i++)
		R.insert(ds.root(i));
	
	for(auto &r : R)
		ans += ds.bad[r];
	
	cout << ans << endl;

	return 0;
}

