#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
vector<pair<int,pair<int,int> > > e;
int par[100005],rem[100005];
long long w[100005];
int find(int x)
{
	if (par[x]!=x)
	par[x]=find(par[x]);
	return par[x];
}
void Union(int x,int y,int c)
{
	x=find(x);
	y=find(y);
	if (x>y)
	swap(x,y);
	if (x!=y)
	{
		par[y]=x;
		w[x]+=w[y];
		rem[x]+=rem[y];
	}
	rem[x]++;
	if (w[x]>=c)
	rem[x]=0;
}
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
	{
		scanf("%lld",&w[i]);
		par[i]=i;
	}
	while (m--)
	{
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		e.push_back({c,{a,b}});
	}
	sort(e.begin(),e.end());
	for (auto p:e)
	Union(p.second.first,p.second.second,p.first);
	printf("%d",rem[1]);
}