#include <bits/stdc++.h>
 
using namespace std;
 
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl

ll n,m,val[100005],par[100005],cnt[100005];
ll u[100005],v[100005],c[100005];
ll in[100005];
bool tak[100005];

int get_par(int i)
{
	if(par[i]==i)
		return i;
	return par[i]=get_par(par[i]);
}

bool cmp(int i,int j)
{
	return c[i]<c[j];
}

int main()
{
	SPEED;		
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>val[i],par[i]=i;
	for(int i=1;i<=m;i++)
		cin>>u[i]>>v[i]>>c[i],in[i]=i;
	sort(in+1,in+m+1,cmp);
	int ans=0;
	for(int i1=1;i1<=m;i1++)
	{
		int i=in[i1];
		int x=get_par(u[i]);
		int y=get_par(v[i]);
		if(x!=y)
			val[y]+=val[x],cnt[y]=cnt[x]+cnt[y],par[x]=y;
		cnt[y]++;
		if(val[y]>=c[i])
			tak[i]=1,ans+=cnt[y],cnt[y]=0;
	}
	cout<<m-ans<<endl;
	return 0;
}