#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <utility>
#define maxn 100005
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int inf = 0x3f3f3f3f;
ll x[maxn];
int n,m,par[maxn],hei[maxn];
struct edge{
	int u,v,w;
	ll y;
	bool operator < (const edge &e)const
	{
		return w < e.w;
	}
}el[maxn];
void ini(){
	for(int i=1;i<=n;i++){
		par[i] = i;
		hei[i] = 1;
	}
}
int fin(int u){
	if(par[u] == u) return u;
	return par[u] = fin(par[u]);
}
ll uni(int u,int v){
	u = fin(u),v = fin(v);
	if(u == v){
		return x[u];
	}else{
		if(hei[u] < hei[v]){
			par[u] = v;
			x[v] += x[u];
			x[u] = 0;
			return x[v];
		}else{
			par[v] = u;
			x[u] += x[v];
			x[v] = 0;
			if(hei[u] == hei[v]) hei[u]++;
			return x[u];
		}
	}
}
vector <P> adj[maxn];//to,cst.
bool vis[maxn];
void dfs(int u,int lim){
	vis[u] = true;
	for(int i=0;i<(int)adj[u].size();i++){
		P e = adj[u][i];
		if(vis[e.first] || e.second > lim) continue;
		dfs(e.first,lim);
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%lld",&x[i]);
	for(int i=1;i<=m;i++){
		scanf("%d%d%d",&el[i].u,&el[i].v,&el[i].w);
		adj[el[i].u].push_back(mp(el[i].v,el[i].w));
		adj[el[i].v].push_back(mp(el[i].u,el[i].w));
	}
	sort(el + 1,el + m + 1);
	ini();
	for(int i=1;i<=m;i++) el[i].y = uni(el[i].u,el[i].v);
	int ans = 0;
	for(int i=m;i>=1;i--){
		if(vis[el[i].u]) continue;
		if(el[i].y >= (ll)el[i].w){
			dfs(el[i].u,el[i].w);
			if(!vis[el[i].v]) dfs(el[i].v,el[i].w);
		}else ans++;
	}
	printf("%d\n",ans);
	return 0;
}