#include<bits/stdc++.h>
using namespace std;
struct line
{
	int s,t;
	long long val;
	bool operator <(line y) const
	{
		return val>y.val;
	}
}a[100001];
long long val[100001],sum[100001];
int rk[100001];
int fa[100001];
inline int findx(int x)
{
	if(x!=fa[x])
		return findx(fa[x]);
	return x;
}
bool v[100001];
int belong[100001];
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	int i;
	for(i=1;i<=n;i++)
		scanf("%lld",&val[i]);
	for(i=1;i<=m;i++)
		scanf("%d%d%lld",&a[i].s,&a[i].t,&a[i].val);
	sort(a+1,a+1+m);
	for(i=1;i<=n;i++)
	{
		fa[i]=i;
		sum[i]=val[i];
	}
	for(i=m;i>=1;i--)
	{
		int fx=findx(a[i].s);
		int fy=findx(a[i].t);
		if(fx!=fy)
		{
			v[i]=true;
			if(rk[fx]<rk[fy])
			{
				int t=fx;
				fx=fy;
				fy=t;
			}
			fa[fy]=fx;
			sum[fx]+=sum[fy];
			if(rk[fx]==rk[fy])
				rk[fx]++;
			belong[i]=fy;
		}
	}
	long long ans=0;
	for(i=1;i<=m;i++)
	{
		int fx=findx(a[i].s);
		if(a[i].val>sum[fx])
		{
			ans++;
			if(v[i])
			{
				sum[fx]-=sum[belong[i]];
				fa[belong[i]]=belong[i];
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}