#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define int long long 
using namespace std;
struct Edge{
	int u,v,w;
	Edge(){}
	Edge(int u,int v,int w):u(u),v(v),w(w){}
	friend bool operator<(Edge a,Edge b)
	{
		return a.w<b.w;
	}
};
const int size=1e5+5;
Edge edges[size];
int val[size];
int sum[size];
int cnt[size];
int fa[size];
int find(int x)
{
	if(x==fa[x]) return x;
	int f=find(fa[x]);
	sum[f]+=sum[x];
	sum[x]=0;
	cnt[f]+=cnt[x];
	cnt[x]=0;
	return fa[x]=f;
}
void merge(int fx,int fy)
{
	if(fx==fy)
		cnt[fy]++;
	else 
	{
		sum[fy]+=sum[fx];
		sum[fx]=0;
		cnt[fy]=cnt[fy]+cnt[fx]+1;
		cnt[fx]=0;
		fa[fx]=fy;
	}
}
int32_t main()
{
	int n,m;
	int ans=0;
	memset(cnt,0,sizeof(cnt));
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++) scanf("%lld",&val[i]),fa[i]=i,sum[i]=val[i];
	for(int i=1;i<=m;i++) scanf("%lld%lld%lld",&edges[i].u,&edges[i].v,&edges[i].w);
	sort(edges+1,edges+1+m);
	for(int i=1;i<=m;i++)
	{
		int x=find(edges[i].u),y=find(edges[i].v);
		merge(x,y);
		if(edges[i].w<=sum[y])
		{
			ans+=cnt[y];
			cnt[y]=0;
		}
	}
	printf("%lld\n",m-ans);
}