#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
struct T{
	ll y,a,b;
	bool operator<(const T&q)const{
		return y<q.y;
	}
};
ll n,m,par[100005],w[100005],k[100005],ans;
T e[100005];
ll find(ll x){
	if(par[x]==x)return x;
	ll y=find(par[x]);
	w[y]+=w[x];
	k[y]+=k[x];
	w[x]=0;
	k[x]=0;
	par[x]=y;
	return y;
}
int main(void){
	scanf("%lld%lld",&n,&m);
	for(int i=0;i<n;i++)scanf("%lld",w+i);
	for(int i=0;i<m;i++){
		scanf("%lld%lld%lld",&e[i].a,&e[i].b,&e[i].y);
		e[i].a--,e[i].b--;
	}
	sort(e,e+m);
	for(int i=0;i<n;i++)par[i]=i;
	for(int i=0;i<m;i++){
		ll a=e[i].a,b=e[i].b,y=e[i].y;
		a=find(a);
		b=find(b);
		if(a==b){
			if(w[a]>=y)ans++;
			else k[a]++;
		}else{
			w[a]+=w[b];
			k[a]+=k[b]+1;
			w[b]=0;
			k[b]=0;
			par[b]=a;
			if(w[a]>=y){
				ans+=k[a];
				k[a]=0;
			}
		}
	}
	printf("%lld\n",m-ans);
}
