#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
const int N=5e5+10;
ll n,m,a[N],A,B,W,head[N],cnt,ans,store[N],tot,sum,b[N],maxn[N];ll w[N];
bool check[N],pd[N],vis[N];
struct edge{ll nxt,to,val,num;}ed[N<<1];
struct edk{
	ll a,b,c;
	edk(ll aa=0,ll bb=0,ll cc=0){a=aa;b=bb;c=cc;}
	bool operator <(const edk&e){return c<e.c;}
}e[N];
inline ll addedge(ll x,ll y,ll w,ll num){
	ed[++cnt].to=y;ed[cnt].nxt=head[x];ed[cnt].val=w;ed[cnt].num=num;head[x]=cnt;
	ed[++cnt].to=x;ed[cnt].nxt=head[y];ed[cnt].val=w;ed[cnt].num=num;head[y]=cnt;}
inline void BFS(ll u){
	queue<ll>q;q.push(u);vis[u]=true;store[++tot]=u;
	while(!q.empty()){
		ll u=q.front();q.pop();
		for(register ll i=head[u];i;i=ed[i].nxt){
			ll v=ed[i].to;
			if(!check[ed[i].num]){check[ed[i].num]=true;e[++sum]=edk(u,v,ed[i].val);}
			if(!vis[v]){vis[v]=true;store[++tot]=v;q.push(v);}
		}
	}
}
inline ll f(ll x){if(x!=b[x])return b[x]=f(b[x]);return x;}
inline ll Solve(ll x){
	tot=sum=0;BFS(x);
	sort(e+1,e+sum+1);
	ll ss=tot,res=0;
	for(register ll i=1;i<=tot;i++){b[store[i]]=store[i];w[store[i]]=a[store[i]];pd[store[i]]=true;}
	for(register ll i=1;i<=sum;i++){
		ll x=e[i].a,y=e[i].b,v=e[i].c;
		ll f1=f(x),f2=f(y);
		if(f1!=f2){
			w[f1]+=w[f2];maxn[f1]=max(maxn[f1],max(maxn[f2],v));
			if(!pd[f2])pd[f2]=true,ss++;
			if(w[f1]<maxn[f1]&&pd[f1])pd[f1]=false,ss--;
			if(w[f1]>=maxn[f1]&&!pd[f1])pd[f1]=true,ss++;
			b[f2]=f1;
		}
		else{
			maxn[f1]=max(maxn[f1],v);
			if(w[f1]<maxn[f1]&&pd[f1])pd[f1]=false,ss--;
			if(w[f1]>=maxn[f1]&&!pd[f1])pd[f1]=true,ss++;
		}
		if(ss==tot)res=max(res,i);
	}
	return res;
}
int main(){
	scanf("%lld%lld",&n,&m);
	for(register ll i=1;i<=n;i++)scanf("%lld",&a[i]);
	for(register ll i=1;i<=m;i++)
		scanf("%lld%lld%lld",&A,&B,&W),addedge(A,B,W,i);
	for(register ll i=1;i<=n;i++)if(!vis[i])ans+=Solve(i);
	printf("%lld\n",m-ans);
	return 0;
}