#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
#define ll long long
const int N=2000050;
vector<int> E[N];
struct DSU
{
	int p[N],sz[N];
	ll val[N];
	void init(){ for(int i=0;i<N;i++) p[i]=i,sz[i]=1;}
	DSU(){ init();}
	int Find(int x){ return x==p[x]?x:Find(p[x]);}
	void Union(int x, int y)
	{
		x=Find(x);y=Find(y);
		if(x==y) return;
		if(sz[x]<sz[y]) swap(x,y);
		p[y]=x;
		val[x]+=val[y];
		sz[x]+=sz[y];
		E[x].push_back(y);
	}
} Tree;
bool was[N];
const int inf=1e9+7;
void DFS(int u, int zs)
{
	if(was[u]) return;
	was[u]=1;
	for(int i=0;i<E[u].size() && i<zs;i++)
	{
		int v=E[u][i];
		if(!was[v]) DFS(v,inf);
	}
}
int w[N],u[N],v[N],x[N],id[N],nod[N],zs[N];
ll sum[N];
bool comp(int i, int j){ return w[i]<w[j];}
int main()
{
	int n,m;
	scanf("%i %i",&n,&m);
	for(int i=1;i<=n;i++) scanf("%i",&x[i]),Tree.val[i]=x[i];
	for(int i=1;i<=m;i++) scanf("%i %i %i",&u[i],&v[i],&w[i]),id[i]=i;
	sort(id+1,id+1+m,comp);
	for(int j=1;j<=m;j++)
	{
		int i=id[j];
		Tree.Union(u[i],v[i]);
		nod[i]=Tree.Find(u[i]);
		sum[i]=Tree.val[nod[i]];
		//printf("%i: %lld\n",i,sum[i]);
		zs[i]=E[nod[i]].size();
	}
	int ans=0;
	for(int j=m;j>=1;j--)
	{
		int i=id[j];
		int d=u[i];
		if(u[i]==nod[i]) d=v[i];
		if(sum[i]<w[i] && !was[d])
		{
            ans++;
		}
		else DFS(nod[i],zs[i]);
	}
	printf("%i\n",ans);
	return 0;
}