#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vector<pii> > vvpii;

#define pb push_back
#define mp make_pair
#define endl '\n'
#define INF (ll)1e10

ll n, m;
ll dsu[100010], weight[100010], cnt[100010];

ll root(ll a){
	if(dsu[a] != a){
		dsu[a] = root(dsu[a]);
	}
	return dsu[a];
}

int main(){
	cin >> n >> m;
	for(ll i = 0; i < n; i++){
		cin >> weight[i];
		dsu[i] = i;
	}
	vector<pair< ll, pair<ll,ll> > > edges;
	for(ll i = 0; i < m; i++){
		ll x, y, z;
		cin >> x >> y >> z;
		edges.emplace_back( mp(z, mp(x-1, y-1) ) );
	}
	sort(edges.begin(), edges.end());
	ll good_edges = 0;
	for(ll i = 0; i < m; i++){
		ll w = edges[i].first;
		ll a = root( edges[i].second.first );
		ll b = root( edges[i].second.second );
		if(a!=b){
			dsu[a] = b;
			weight[b] = min(weight[b]+weight[a],INF);
			cnt[b] += cnt[a];
		}
		cnt[b]++;
		if(weight[b] >= w){
			good_edges += cnt[b];
			cnt[b] = 0;
		}
	}
	cout << m - good_edges;
}