#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<vector>

using namespace std;

#define N 201000
#define ll long long
#define ls (now<<1)
#define rs ((now<<1)|1)
#define RG register

inline int read(){
    RG int x=0,o=1; RG char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=((x<<3)+(x<<1))+ch-'0',ch=getchar();
    return x*o;
}

int n,m,val[N],fa[N],vis[N],siz[N],tot; ll sum[N];
struct navi { int x,y,w; } a[N],b[N];
inline bool cmp(navi x,navi y) { return x.w<y.w; }
inline int Find(int x) { if(fa[x]^x) return Find(fa[x]); return fa[x]; }

struct joker { int i,w; } cps[N],cpz[N],cpf[N];
inline void Cp(int op,int i,int w,int id){
	if(op==1) cps[id]=(joker) { i,w };
	if(op==2) cpz[id]=(joker) { i,w };
	if(op==3) cpf[id]=(joker) { i,w };
}

int main(){
	n=read(),m=read();
	for(RG int i=1;i<=n;++i) val[i]=read(),fa[i]=i,sum[i]=val[i],siz[i]=1;
	for(RG int i=1;i<=m;++i) a[i]=(navi) { read(),read(),read() };
	sort(a+1,a+1+m,cmp);
	for(RG int i=1;i<=m;++i){
		int fx=Find(a[i].x),fy=Find(a[i].y);
		if(fx^fy){
			b[++tot]=a[i];
			if(siz[fx]<siz[fy]) Cp(1,fy,sum[fy],tot),Cp(2,fy,siz[fy],tot),Cp(3,fx,fa[fx],tot),
									fa[fx]=fy,siz[fy]+=siz[fx],sum[fy]+=sum[fx];
			else Cp(1,fx,sum[fx],tot),Cp(2,fx,siz[fx],tot),Cp(3,fy,fa[fy],tot),
					 fa[fy]=fx,siz[fx]+=siz[fy],sum[fx]+=sum[fy];
		}
	}   int cp=0,ans=0;
	for(RG int i=tot;i;--i){
		int Y=Find(b[i].y); if(sum[Y]>=b[i].w) continue ; vis[i]=1;
		siz[cpz[i].i]=cpz[i].w,sum[cps[i].i]=cps[i].w,fa[cpf[i].i]=cpf[i].w;
	}	for(RG int i=1;i<=tot;++i) if(!vis[i]) b[++cp]=b[i];
	for(RG int i=1;i<=m;++i){
		int fx=Find(a[i].x),fy=Find(a[i].y);
		if((fx^fy)||(sum[fx]<a[i].w)) { ++ans; continue ; }
	}   printf("%d\n",ans);
}
