#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXSIZE=10000020;
int bufpos;
char buf[MAXSIZE];
#define NEG 0
void init(){
	#ifdef LOCAL
		freopen("E.txt","r",stdin);
	#endif
	buf[fread(buf,1,MAXSIZE,stdin)]='\0';
	bufpos=0;
}
#if NEG
int readint(){
	bool isneg;
	int val=0;
	for(;!isdigit(buf[bufpos]) && buf[bufpos]!='-';bufpos++);
	bufpos+=(isneg=buf[bufpos]=='-');
	for(;isdigit(buf[bufpos]);bufpos++)
		val=val*10+buf[bufpos]-'0';
	return isneg?-val:val;
}
#else
int readint(){
	int val=0;
	for(;!isdigit(buf[bufpos]);bufpos++);
	for(;isdigit(buf[bufpos]);bufpos++)
		val=val*10+buf[bufpos]-'0';
	return val;
}
#endif
char readchar(){
	for(;isspace(buf[bufpos]);bufpos++);
	return buf[bufpos++];
}
int readstr(char* s){
	int cur=0;
	for(;isspace(buf[bufpos]);bufpos++);
	for(;!isspace(buf[bufpos]);bufpos++)
		s[cur++]=buf[bufpos];
	s[cur]='\0';
	return cur;
}
const int maxn=100002;
int fa[maxn];
ll sum[maxn];
int sz[maxn];
int getf(int x){
	return fa[x]==x?x:fa[x]=getf(fa[x]);
}
struct edge{
	int u,v,w;
	bool operator <(const edge& rhs)const{
		return w<rhs.w;
	}
}e[maxn];
int main(){
	init();
	int n=readint(),m=readint();
	for(int i=1;i<=n;i++)
		fa[i]=i,sum[i]=readint();
	for(int i=1;i<=m;i++)
		e[i].u=readint(),e[i].v=readint(),e[i].w=readint();
	sort(e+1,e+m+1);
	int ans=0;
	for(int i=1;i<=m;i++){
		int u=e[i].u,v=e[i].v,w=e[i].w;
		u=getf(u),v=getf(v);
		if (u!=v)
			fa[u]=v,sz[v]+=sz[u],sum[v]+=sum[u];
		sz[v]++;
		if (w<=sum[v])
			ans+=sz[v],sz[v]=0;
	}
	printf("%d",m-ans);
}