#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=1e5+10;
struct point{
	int x,y,z;
	bool operator <(const point &rhs) const{
		return z<rhs.z;
	}
}b[maxn];
int a[maxn],fa[maxn],sum[maxn];
ll tot[maxn];
int find(int x){
	if(fa[x]==x) return x;
	return fa[x]=find(fa[x]);
}
int main(){
	int n=read(),m=read();
	REP(i,1,n) fa[i]=i,tot[i]=read();
	REP(i,1,m) b[i].x=read(),b[i].y=read(),b[i].z=read();
	sort(b+1,b+m+1);
	REP(i,1,m){
		int x=b[i].x,y=b[i].y,z=b[i].z;
		x=find(x),y=find(y);
		if(x==y) sum[x]+=(z>tot[x]);
		else{
			fa[x]=y,tot[y]+=tot[x],sum[y]+=sum[x];
			if(z>tot[y]) sum[y]++;
			else sum[y]=0;
		}
	}
	int ans=0;
	REP(i,1,n) if(fa[i]==i) ans+=sum[i];
	printf("%d\n",ans);
	return 0;
}
