#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<ll, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

ll ufp[100100];
ll ufr[100100];

int ufind(int p){
	if(ufp[p] != p){
		ufp[p] = ufind(ufp[p]);
	}
	return ufp[p];
}

void unionf(int x, int y){
	x = ufind(x);
	y = ufind(y);
	if(x == y){
		return;
	}
	if(ufr[x]>ufr[y]){
		ufp[y] = x;
		ufr[x] += ufr[y];
	}else{
		ufp[x] = y;
		ufr[y] += ufr[x];
	}
}

vector<E> g,f[100100];

bool c[100100],r[100100];

queue<int> q;

bool comp(E a, E b){
	return (a.first<b.first);
}

int main(void){
	int n,m,i,j,u,v,ans=0;
	ll s=0ll,a;
	cin >> n >> m;
	fill(c,c+100100,false);
	fill(r,r+100100,false);
	for(i=0; i<n; ++i){
		cin >> ufr[i];
		ufp[i] = i;
	}
	for(i=0; i<m; ++i){
		cin >> u >> v >> a;
		--u; --v;
		g.push_back(E(a,P(u,v)));
	}
	sort(g.begin(),g.end(),comp);
	for(i=0; i<m; ++i){
		a = g[i].first;
		u = g[i].second.first;
		v = g[i].second.second;
		f[u].push_back(E(a,P(v,i)));
		f[v].push_back(E(a,P(u,i)));
		unionf(u,v);
		if(ufr[ufind(u)]>=a){
			c[i] = true;
		}
	}
	for(i=(m-1); i>=0; --i){
		if(r[i] || (!c[i])){
			continue;
		}
		a = g[i].first;
		q.push(g[i].second.first);
		q.push(g[i].second.second);
		r[i] = true;
		while(!q.empty()){
			u = q.front();
			q.pop();
			for(j=(f[u].l_ength()-1); j>=0; --j){
				if(r[f[u][j].second.second] || f[u][j].first > a){
					continue;
				}
				r[f[u][j].second.second] = true;
				q.push(f[u][j].second.first);
			}
		}
	}
	for(i=0; i<m; ++i){
		if(r[i]){
			continue;
		}
		++ans;
	}
	cout << ans << endl;
	return 0;
}
