#include<bits/stdc++.h>

using namespace std;

typedef long long LL;
#define N 300000

LL n,m,a[N],f[N],fa[N],cnt,bel[N],ans,c[N][2];
struct node{
	LL x,y,z;
	bool operator < (const node &p) const{
		return z<p.z;
	}
}b[N];

LL gfa(LL x){return x==fa[x]?x:fa[x]=gfa(fa[x]);}

void merge(LL x,LL y,LL z){
	x=gfa(x); y=gfa(y);
	if (x!=y){
		fa[x]=fa[y]=++cnt;
		fa[cnt]=cnt; a[cnt]=z;
		f[cnt]=f[x]+f[y];
		c[cnt][0]=x; c[cnt][1]=y;
	}
}

void dfs(LL u,LL fl){
	if (u<=n){bel[u]=fl; return;}
	if (fl||f[u]>=a[u]){
		dfs(c[u][0],fl?fl:u);
		dfs(c[u][1],fl?fl:u);
		return;
	}
	dfs(c[u][0],0);
	dfs(c[u][1],0);
}

int main(){
	scanf("%lld%lld",&n,&m);
	for (LL i=1;i<=n;++i){scanf("%lld",a+i); f[i]=a[i];}
	for (LL i=1;i<=m;++i) scanf("%lld%lld%lld",&b[i].x,&b[i].y,&b[i].z);
	sort(b+1,b+m+1);
	cnt=n;
	for (int i=1;i<=n;++i) fa[i]=i;
	for (LL i=1;i<=m;++i) merge(b[i].x,b[i].y,b[i].z);
	dfs(cnt,0);
	for (LL i=1;i<=m;++i) ans+=(bel[b[i].x]!=bel[b[i].y])|(b[i].z>f[bel[b[i].x]]);
	printf("%lld\n",ans);
	
	return 0;
}
			