#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>

typedef long long LL;

const int N=100005;

int n,m,cnt,last[N],a[N],f[N],now,op[N],vis[N];
LL g[N];
struct data{int x,y,z;}b[N];
struct edge{int to,next,w;}e[N*2];

bool cmp(data a,data b)
{
	return a.z<b.z;
}

int find(int x)
{
	if (f[x]==x) return x;
	else return f[x]=find(f[x]);
}

void addedge(int u,int v,int w)
{
	e[++cnt].to=v;e[cnt].w=w;e[cnt].next=last[u];last[u]=cnt;
	e[++cnt].to=u;e[cnt].w=w;e[cnt].next=last[v];last[v]=cnt;
}

void dfs(int x)
{
	for (int i=last[x];i;i=e[i].next)
		if (!op[i/2]&&e[i].w<=now) op[i/2]=1,dfs(e[i].to);
}

int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=m;i++) scanf("%d%d%d",&b[i].x,&b[i].y,&b[i].z);
	std::sort(b+1,b+m+1,cmp);
	cnt=1;
	for (int i=1;i<=m;i++) addedge(b[i].x,b[i].y,b[i].z);
	for (int i=1;i<=n;i++) f[i]=i,g[i]=a[i];
	for (int i=1;i<=m;i++)
	{
		int x=find(b[i].x),y=find(b[i].y);
		if (x!=y) f[x]=y,g[y]+=g[x];
		if (g[y]>=b[i].z) vis[i]=1;
	}
	for (int i=m;i>=1;i--)
		if (!op[i]&&vis[i]) now=b[i].z,op[i]=1,dfs(b[i].x),dfs(b[i].y);
	int ans=0;
	for (int i=1;i<=m;i++) if (!op[i]) ans++;
	printf("%d\n",ans);
	return 0;
}