#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 100000 
#define LL long long
int n,m,ans;
LL w[MAXN+5];
int fa[MAXN+5],cnt[MAXN+5];
struct edge{
	int u,v,w;
}a[MAXN+5];
bool cmp(edge s1,edge s2){return s1.w<s2.w;}
int xfind(int x){return (fa[x]==x)?x:fa[x]=xfind(fa[x]);}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{scanf("%lld",&w[i]);fa[i]=i;}
	for(int i=1;i<=m;i++)
		scanf("%d%d%d",&a[i].u,&a[i].v,&a[i].w);
	sort(a+1,a+m+1,cmp);
	for(int i=1;i<=m;i++)
	{
		int x=xfind(a[i].u),y=xfind(a[i].v);
		if(x!=y)
		{
			w[x]+=w[y];
			cnt[x]+=cnt[y];
			w[y]=0,cnt[y]=0;
			fa[y]=x;
		}
		cnt[x]++;
		if(w[x]>=a[i].w)
		{
			ans+=cnt[x];
			cnt[x]=0;
		}
	}
	printf("%d",m-ans);
}