#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
using namespace std;
const int maxd=1000000007,N=100000;
const double pi=acos(-1.0);
typedef long long ll;
struct node{
	int u,v,w;
}sq[100100];

bool operator < (const node &p,const node &q)
{
	return p.w<q.w;
}

int n,m,fa[100100],cnt[100100],p[100100],ans=0;
ll sum[100100];

int read()
{
	int x=0,f=1;char ch=getchar();
	while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
	while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
	return x*f;
}

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

int main()
{
	n=read();m=read();int i;
	for (i=1;i<=n;i++) {p[i]=read();sum[i]=p[i];}
	memset(cnt,0,sizeof(cnt));
	for (i=1;i<=n;i++) fa[i]=i;
	for (i=1;i<=m;i++)
	{
		sq[i].u=read();sq[i].v=read();sq[i].w=read();
	}
	sort(sq+1,sq+1+m);
	for (i=1;i<=m;i++)
	{
		int x=sq[i].u,y=sq[i].v,
	    	fx=find(x),fy=find(y);
		if (fx!=fy)
		{
			cnt[fx]+=(cnt[fy]+1);
			sum[fx]+=sum[fy];
			cnt[fy]=0;sum[fy]=0;
			fa[fy]=fx;
		}
		else cnt[fx]++;
		if (sum[fx]>=sq[i].w)
		{
			ans+=cnt[fx];
			cnt[fx]=0;
		}
	}
	printf("%d",m-ans);
	return 0;
}

