#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1e5+10;
int 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{int nxt,to,val,num;}ed[N<<1];
struct edk{
	int a,b,c;
	edk(int aa=0,int bb=0,int cc=0){a=aa;b=bb;c=cc;}
	bool operator <(const edk&e){return c<e.c;}
}e[N];
inline int addedge(int x,int y,int w,int 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 DFS(int u){
	vis[u]=true;store[++tot]=u;
	for(register int i=head[u];i;i=ed[i].nxt){
		int 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])DFS(v);
	}
}
inline int f(int x){if(x!=b[x])return b[x]=f(b[x]);return x;}
inline int Solve(int x){
	tot=sum=0;DFS(x);
	sort(e+1,e+sum+1);
	int ss=tot,res=0;
	for(register int i=1;i<=tot;i++){b[store[i]]=store[i];w[store[i]]=a[store[i]];pd[store[i]]=true;}
	for(register int i=1;i<=sum;i++){
		int x=e[i].a,y=e[i].b,v=e[i].c;
		int 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],max(maxn[f2],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("%d%d",&n,&m);
	for(register int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(register int i=1;i<=m;i++)
		scanf("%d%d%d",&A,&B,&W),addedge(A,B,W,i);
	for(register int i=1;i<=n;i++)if(!vis[i])ans+=Solve(i);
	printf("%d\n",m-ans);
	return 0;
}