#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;


/*
辺を切り離した時の頂点の総和を高速に計算できないといけない
*/

struct D{
	ll a,b,c,id;
};
bool operator<(const D &lhs, const D &rhs){//全順序を定めないと，{1,0,0}=={1,1,0}
	if(lhs.c < rhs.c){
		return true;
	}else if(lhs.c == rhs.c){
		if(lhs.id < rhs.id){
			return true;
		}
	}
	return false;
}

ll n,m,ans=0,use[100010]={},y[100010];
vector<int> x(100010),v[100010],id[100010];
vector<D> cand;
D edge[100010];

struct UnionFind{
	int n;
	vector<ll> sum,r,p;
	UnionFind(){}
	UnionFind(int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);sum=x;}
	int find(int x){
		return (x==p[x]?x:p[x]=find(p[x]));
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
	void unite(int x,int y){
		x=find(x);y=find(y);
		if(x==y) return;
		if(r[x]<r[y]) swap(x,y);
		r[x]+=r[y];
		sum[x]+=sum[y];
		p[y]=x;
	}
	ll energy(int x){
		return sum[find(x)];
	}
};

int main(void){
	cin>>n>>m;
	reg(i,1,n)cin>>x[i];
	reg(i,1,m){
		ll a,b,c;
		cin>>a>>b>>c;
		edge[i]={a,b,c,i};
		v[a].push_back(b);
		v[b].push_back(a);
		id[a].push_back(i);
		id[b].push_back(i);
		y[i]=c;
	}
	//
	sort(edge+1,edge+1+m);
	UnionFind f(n+1);
	//
	reg(i,1,m){
		f.unite(edge[i].a,edge[i].b);
		ll sum = f.energy(edge[i].a);
		if(sum>=edge[i].c)cand.push_back(edge[i]);
		// cout<<sum<<endl;
		// printf("%lld,%lld,%lld\n",edge[i].a,edge[i].b,edge[i].c);
	}
	irep(i,cand.size()){
		if(use[cand[i].id]==0){
			//y[cand[i]]以下の辿れる辺全部使う
			queue<ll> Q;
			Q.push(cand[i].a);
			Q.push(cand[i].b);
			use[cand[i].id]=1;
			while(!Q.empty()){
				ll p = Q.front();Q.pop();
				rep(j,v[p].size()){
					if(use[id[p][j]]==0 && y[id[p][j]]<=y[cand[i].id]){
						use[id[p][j]]=1;
						Q.push(v[p][j]);
					}
				}
			}
		}
	}
	reg(i,1,m)if(use[i]==0)ans++;
	cout<<ans<<endl;
	return 0;
}