#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pa pair<int,int>
const int Maxn=100010;
const int inf=2147483647;
int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x*f;
}
int n,m;
int fa[Maxn],cnt[Maxn],a[Maxn];
LL sum[Maxn];
struct Edge{int x,y,d;}e[Maxn];
bool cmp(Edge a,Edge b){return a.d<b.d;}
int findfa(int x){return((fa[x]==x)?x:fa[x]=findfa(fa[x]));}
int main()
{
	n=read(),m=read();
	for(int i=1;i<=n;i++)a[i]=read();
	for(int i=1;i<=m;i++)e[i].x=read(),e[i].y=read(),e[i].d=read();
	sort(e+1,e+1+m,cmp);
	for(int i=1;i<=n;i++)fa[i]=i,sum[i]=a[i],cnt[i]=0;
	int ans=0;
	for(int i=1;i<=m;i++)
	{
		int fx=findfa(e[i].x),fy=findfa(e[i].y);
		if(fx!=fy)
		{
			fa[fy]=fx;
			sum[fx]+=sum[fy];
			cnt[fx]+=cnt[fy]+1;
			if(sum[fx]>=e[i].d)ans+=cnt[fx],cnt[fx]=0;
		}
		else
		{
			cnt[fx]++;
			if(sum[fx]>=e[i].d)ans+=cnt[fx],cnt[fx]=0;
		}
	}
	printf("%d",m-ans);
}