#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

vector<P>E[200000];
int x[200000];
struct st{int a,b,c;};

struct UnionFind{
	vector<int>par;
	vector<ll>sum;
	UnionFind(int n){
		par=vector<int>(n);
		sum=vector<ll>(n);
		rep(i,n){
			par[i]=i;
			sum[i]=x[i];
		}
	}
	int find(int x){
		if(par[x]==x)return x;
		return par[x]=find(par[x]);
	}
	void unite(int x,int y){
		x=find(x);y=find(y);
		if(x==y)return;
		par[x]=y;
		sum[y]+=sum[x];
	}
	ll calc(int x){
		return sum[find(x)];
	}
};

set<P>se;
bool used[200000];

void dfs(int v,int w){
	used[v]=true;
	for(auto p:E[v]){
		if(p.first<=w){
			se.insert(P(min(p.second,v),max(p.second,v)));
			if(!used[p.second]){
				dfs(p.second,w);
			}
		}
	}
}

bool b[200000];
int main(){
	int n,m;cin>>n>>m;
	rep(i,n)scanf("%d",&x[i]);
	vector<st>v;
	rep(i,m){
		int a,b,y;scanf("%d%d%d",&a,&b,&y);a--;b--;
		v.push_back({a,b,y});
		E[a].push_back(P(y,b));
		E[b].push_back(P(y,a));
	}
	sort(v.begin(),v.end(),[](st a,st b){return a.c<b.c;});
	UnionFind uf(n);
	rep(i,m){
		uf.unite(v[i].a,v[i].b);
		if(uf.calc(v[i].a)>=v[i].c){
			b[i]=true;
		}
	}
	for(int i=m-1;i>=0;i--){
		if(b[i]){
			dfs(v[i].a,v[i].c);
			dfs(v[i].b,v[i].c);
		}
	}
	cout<<m-se.size()<<endl;
}
