#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#define ll long long
using namespace std;
const int N=2e5;
struct edge{int fr,to,w;}a[N],sta[N];
int n,m,val[N],fa[N];
int siz[N],cnt,top,ans;
ll sum[N];
int cmp(const edge&A,const edge&B) {return A.w<B.w;}
int find(int x) {return fa[x]==x?x:find(fa[x]);}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&val[i]);
		fa[i]=i,siz[i]=1,sum[i]=val[i];
	}
	for(int i=1,x,y,w;i<=m;i++)
	{
		scanf("%d%d%d",&x,&y,&w);
		a[++cnt]=(edge){x,y,w};
	}
	sort(a+1,a+cnt+1,cmp);

	for(int i=1;i<=cnt;i++)
	{
		int x=a[i].fr,y=a[i].to;
		x=find(x);y=find(y);
		if(x==y) continue;
		if(siz[x]>siz[y]) swap(x,y);
		sta[++top]=(edge){x,y,a[i].w};
		fa[x]=y;siz[y]+=siz[x];sum[y]+=sum[x];
	}
	for(int i=top;i>=1;i--)
	{
		int x=sta[i].fr,y=sta[i].to;
		ll v=sum[find(y)],val=sta[i].w;
		if(v<val) fa[x]=x,siz[y]-=siz[x],sum[y]-=sum[x];
	}
	for(int i=1;i<=m;i++)
	{
		int x=a[i].fr,y=a[i].to;
		if(find(x)!=find(y)) ans++;
		else if(a[i].w>sum[find(x)]) ans++;
	}
	cout<<ans<<endl;
}
