//int -> ll
//http://web.mit.edu/~ecprice/acm/acm08/notebook.html#file12
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include<bits/stdc++.h>
typedef long long ll;
#define x first
#define y second
#define all(aaa) (aaa).begin(),(aaa).end()
#define REP(i,sss,eee) for(int i=sss;i<=eee;++i)
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
#define N 1000000007
using namespace __gnu_pbds;
using namespace std;
template <class T>
T MAX(T a, T b){return ((a>b)?a:b);}
template <class T>
T MIN(T a, T b){return ((a<b)?a:b);}
template <class T>
T MOD(T a){return ((a>=0)?a:(-1*a));}
template <class T>
void SWAP(T &a,T &b){T temp=a;a=b;b=temp;}
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
long long ex(long long a, long long b){
	if(b==0||a==1){return 1;}
	if(a==0||b==1){return a;}
	long long tmp=ex(a,(b/2));
	if(b%2){return ((((tmp*tmp)%N)*a)%N);}
	else{return ((tmp*tmp)%N);}
}
long long inv(long long k){
	if(k==1){return 1;}
	else{return ex(k,N-2);}
}
/*****************default********************/
std::vector<int> par,num,var,sum,rem;
//num -> rank sum->tot joined vertices
std::vector<tuple<int,int,int>> edg;
bool cmp(tuple<int,int,int> q,tuple<int,int,int> w)
{
	return ((get<2>(q))<(get<2>(w)));
}
int findpar(int a)
{
	if(a==par[a]){return a;}
	return findpar(par[par[a]]);
}
int unite(int a, int b)
{
	int p1=findpar(a),p2=findpar(b);
	if(num[p1]<num[p2]){SWAP(p1,p2);}
	num[p1]+=num[p2];
	sum[p1]+=sum[p2];
	rem[p1]+=rem[p2];
	par[p2]=p1;
	return 0;
}
int solve()
{
	int n,m;cin>>n>>m;
	par.resize(n+1);num.resize(n+1,1);sum.resize(n+1,0);
	rem.resize(n+1,0);
	iota(par.begin(),par.end(),0);
	var.resize(n+1);
	REP(i,1,n)
	{
		cin>>var[i];sum[i]=var[i];
	}
	REP(i,1,m)
	{
		int a,b,c;cin>>a>>b>>c;
		edg.pb(make_tuple(a,b,c));
	}
	sort(edg.begin(),edg.end(),cmp);
	int ans=0;
	for(auto it:edg)
	{
		auto [a,b,c]=it;
		if(findpar(a)!=findpar(b))
		{
			unite(a,b);
		}
		++rem[findpar(a)];
		if(sum[findpar(a)]>=c)
		{
			ans+=rem[findpar(a)];
			rem[findpar(a)]=0;
		}
	}
	cout<<(m-ans)<<"\n";
}
signed main(){
	speed
	int tt=1;
	//cin>>tt;
	while(tt--)
	{
		solve();
	}
	return 0;
}