#include<bits/stdc++.h>
#pragma GCC target ("avx")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()

template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr int mod = 1e9+7;
constexpr long long inf = 3e18;

struct UnionFind{
	vector<int>par,size;
	int find(int x){
		return (par[x]==x?x:par[x]=find(par[x]));
	}
	void merge(int x,int y){
		x=find(x);y=find(y);
		if(x==y)return;
		if(size[x]<size[y]){
			par[x]=y;
			size[y]+=size[x];
		}else {
			par[y]=x;
			size[x]+=size[y];
		}
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
	int getsize(int x){return size[find(x)];}
	UnionFind(int x,vector<int>&v):size(v){
		rep(i,x){
			par.push_back(i);
		}
	}
};
struct Edge{
	int from,to,weight;
	bool operator<(Edge &e){return weight<e.weight;}
};
struct Edge2{
	int to,weight,idx;
};
int N,M;
vector<int>X;
vector<Edge2>G[100005];
Edge E[100005];
bool ok[100005],usedV[100005],usedE[100005];
void dfs(int x,int MX){
	usedV[x]=true;
	for(Edge2 i:G[x])if(i.weight<=MX){
		if(!usedE[i.idx])usedE[i.idx]=true;
		if(!usedV[i.to])dfs(i.to,MX);
	}
}
signed main(){
	cin>>N>>M;
	X.resize(N);
	for(int &i:X)cin>>i;
	rep(i,M){
		cin>>E[i].from>>E[i].to>>E[i].weight;
		E[i].from--;E[i].to--;
	}
	UnionFind uf(N,X);
	sort(E,E+M);
	rep(i,M){
		uf.merge(E[i].from,E[i].to);
		if(uf.getsize(E[i].from)>=E[i].weight)ok[i]=true;
		G[E[i].from].push_back({E[i].to,E[i].weight,i});
		G[E[i].to].push_back({E[i].from,E[i].weight,i});
	}
	rev(i,M){
		if(!usedV[i]&&ok[i])dfs(E[i].from,E[i].weight);
	}
	int ans=0;
	rep(i,M)ans+=!usedE[i];
	cout<<ans<<endl;
}