#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 (int)1e9
#define EPS 1e-9
#define gcd __gcd
#define rs resize
#define FOR(i,a,b) for(int i = a; i < b; i++)
#define by(T, x) [](const T& a, const T& b) { return a.x < b.x; } //for struct sorting

void printV(vector<int> v){
	for(int i = 0; i < v.size(); i++){
		cout << v[i] << " " ;
	}
	cout << endl;
}

void print2V(vvi v){
	FOR(i, 0, v.size()){
		FOR(j, 0, v[i].size()){
			cout << v[i][j] << " ";
		}
		cout << endl;
	}
}

int n, m;
ll dsu[100010], weight[100010], cnt[100010];
vector<pair< int, pair<int,int> > > edges;

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

int main(){
	cin >> n >> m;
	for(int i = 0; i < n; i++){
		cin >> weight[i];
		dsu[i] = i;
	}
	int a, b, w;
	for(int i = 0; i < m; i++){
		cin >> a >> b >> w;
		edges.push_back( mp(w, mp(a-1, b-1) ) );
	}
	sort(edges.begin(), edges.end());
	int good_edges = 0;
	for(int i = 0; i < m; i++){
		w = edges[i].first;
		a = root( edges[i].second.first );
		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;
}