#include<bits/stdc++.h>
#define int long long
#define N 500005
using namespace std;
int n,m,ans,fa[N],sz[N],val[N],sum[N];
struct node{int x,y,d;}a[N];
inline bool cmp(node aa,node bb){return aa.d<bb.d;}
int find(int x){
	if (x==fa[x]) return x;
	fa[x]=find(fa[x]);
	sum[fa[x]]+=sum[x];
	sz[fa[x]]+=sz[x];
	sum[x]=sz[x]=0;
	return fa[x];
}
signed main(){
	scanf("%lld%lld",&n,&m);
	for (int i=1;i<=n;i++) scanf("%lld",&val[i]);
	for (int i=1;i<=m;i++) scanf("%lld%lld%lld",&a[i].x,&a[i].y,&a[i].d);
	for (int i=1;i<=n;i++) fa[i]=i,sum[i]=val[i];
	sort(a+1,a+m+1,cmp);
	for (int i=1;i<=m;i++){
		int fx=find(a[i].x);
		int fy=find(a[i].y);
		if (fx==fy){
			sz[fx]++;
			if (a[i].d<=sum[fx]) ans+=sz[fx],sz[fx]=0;
		}
		else {
			fa[fx]=fy;
			sum[fy]+=sum[fx];
			sz[fy]+=sz[fx]+1;
			sz[fx]=sum[fx]=0;
			if (a[i].d<=sum[fy]){
				ans+=sz[fy];
				sz[fy]=0;
			}
		}
	}
	printf("%lld\n",m-ans);
	return 0;
}