#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=100010;
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
int n,m,a[maxn],fa[maxn],cnt[maxn],ans;
ll sum[maxn];
struct edge{
	int u,v,w;
	bool operator<(const edge &e)const{
		return w<e.w;
	}
}e[maxn];
inline int read(){
	int x=0,f=0;
	char ch=getchar();
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
int getfa(int x){
	return x==fa[x]?x:fa[x]=getfa(fa[x]);
}
int main(){
	n=read();m=read();
	FOR(i,1,n) a[i]=read();
	FOR(i,1,m) e[i].u=read(),e[i].v=read(),e[i].w=read();
	sort(e+1,e+m+1);
	FOR(i,1,n) sum[i]=a[i],fa[i]=i;
	FOR(i,1,m){
		int u=e[i].u,v=e[i].v;
		int uf=getfa(u),vf=getfa(v);
		if(uf==vf) cnt[uf]++;
		else{
			sum[uf]+=sum[vf];
			cnt[uf]+=cnt[vf]+1;
			fa[vf]=uf;
		}
		if(e[i].w<=sum[uf]){
			ans+=cnt[uf];
			cnt[uf]=0;
		}
	}
	printf("%d\n",m-ans);
}