#include <bits/stdc++.h>
using namespace std;
long long n,m,i,j,sz[100005],f[100005],sum[100005],fa[100005],px[100005],py[100005],pz[100005],vis[100005],tag[100005];
struct ed
{
	long long id,z;
}a[100005];
bool cmp(ed x,ed y){return x.z<y.z;}
long long fnd(long long x)
{
	if (fa[x]==x) return x;
	return fnd(fa[x]);
}
stack<long long> sx,sy;
void merge(long long x,long long y)
{
	x=fnd(x);y=fnd(y);
	if (sz[x]>sz[y]) swap(x,y);
	sum[y]+=sum[x];
	fa[x]=y;
	if (sz[x]==sz[y]) sz[y]++;
	sx.push(x);
	sy.push(y);
}
void chexiao()
{
	long long x=sx.top(),y=sy.top();
	sx.pop();sy.pop();
	fa[x]=x;sum[y]-=sum[x];
	if (tag[y]) tag[x]=1;
}
int main()
{
	scanf("%lld%lld",&n,&m);
	for (i=1;i<=n;i++) {scanf("%lld",&sum[i]);}
	for (i=1;i<=m;i++)
	{
		scanf("%lld%lld%lld",&px[i],&py[i],&pz[i]);
		a[i]=(ed){i,pz[i]};
	}
	for (i=1;i<=n;i++) {sz[i]=1;fa[i]=i;}
	sort(a+1,a+m+1,cmp);
	for (i=1;i<=m;i++)
	{
		long long t=a[i].id;
		if (fnd(px[t])!=fnd(py[t]))
		{
			merge(px[t],py[t]);
			vis[t]=1;
		}
	}
	long long ans=0;
	for (i=m;i;i--)
	{
		long long t=a[i].id;
		if (tag[fnd(px[t])]||sum[fnd(px[t])]>=pz[t]) tag[fnd(px[t])]=1; else ans++;
		if (vis[t]) chexiao();
	}
	cout<<ans<<endl;
	return 0;
}