#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline LL read()
{
	LL f=1,x=0;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 stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x);putchar(' ');}
inline void pr2(int x){write(x);putchar('\n');}
const int MAXN=100005;
struct edge
{
	int x,y,c;
	int p,q;LL t1,t2;
}E[MAXN],lk[MAXN];int cnt;

int rt[MAXN],tot[MAXN],n,m,cal[MAXN];LL sum[MAXN];
int findrt(int x){return rt[x]==x?rt[x]:findrt(rt[x]);}
bool cmp(edge n1,edge n2){return n1.c<n2.c;}

int main()
{
	n=read();m=read();
	for(int i=1;i<=n;i++)cal[i]=read();
	for(int i=1;i<=m;i++)E[i].x=read(),E[i].y=read(),E[i].c=read();
	sort(E+1,E+1+m,cmp);
	for(int i=1;i<=n;i++)sum[i]=cal[i],tot[i]=1,rt[i]=i;
	for(int i=1;i<=m;i++)
	{
		int p=findrt(E[i].x),q=findrt(E[i].y);
		if(p!=q)
		{
			if(tot[p]>tot[q])swap(p,q);
			rt[p]=q;
			
			lk[++cnt]=E[i];
			lk[cnt].p=p;lk[cnt].q=q;lk[cnt].t1=sum[p];lk[cnt].t2=sum[q];
			
			sum[q]+=sum[p];tot[q]+=tot[p];
		}
	}
	for(int i=cnt;i>=1;i--)
	{
		LL s=sum[findrt(lk[i].x)];
		if(s<lk[i].c)
		{
			rt[lk[i].p]=lk[i].p;rt[lk[i].q]=lk[i].q;
			sum[lk[i].p]=lk[i].t1;sum[lk[i].q]=lk[i].t2;
		}
	}
	int ans=0;
	for(int i=1;i<=m;i++)
	{
		int p=findrt(E[i].x),q=findrt(E[i].y);
		if(p==q)
		{
			if(sum[p]>=E[i].c)ans++;
		}
	}
	pr2(m-ans);
	return 0;
}

