#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sqr(x) ((x)*(x))
#define mp make_pair
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define getchar gc
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void wri(ll a){write(a); putchar(' ');}
inline void writeln(ll a){write(a); puts("");}
const int N=100005;
ll sz[N];
int f[N],ans[N],fa[N];
pair<int,pair<int,int> > e[N];
inline int gf(int x){
	return fa[x]==x?x:fa[x]=gf(fa[x]);
}
signed main(){
	int n=read(),m=read();
	for(int i=1;i<=n;i++)sz[fa[i]=i]=read();
	for(int i=1;i<=m;i++){
		int s=read(),t=read(),w=read();
		e[i]=mp(w,mp(s,t));
	}
	sort(&e[1],&e[m+1]);
	int cnt=0;
	for(int i=1;i<=m;i++){
		int s=e[i].second.first,t=e[i].second.second,w=e[i].first;
		int tx=gf(s),ty=gf(t);
		if(tx==ty){if(sz[tx]<w){f[tx]++;cnt++;} continue;}
		fa[tx]=ty; sz[ty]+=sz[tx]; f[ty]+=f[tx]; f[ty]++; cnt++; //cout<<sz[ty]<<" "<<cnt<<endl;
		if(sz[ty]>=w){cnt-=f[ty]; f[ty]=0;}
	}
	cout<<cnt<<endl;
}