#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
typedef long long ll;
int n,m,g[N],i,ans,nw;
ll a[N];
int rr[N];
struct edge{
	int x,y,z;
	bool operator<(const edge&rhs)const{
		return z<rhs.z;
	}
}e[N];
int gfa(int x){return g[x]==x?x:g[x]=gfa(g[x]);}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	cin>>n>>m;for(i=1;i<=n;++i)g[i]=i,cin>>a[i];
	for(i=1;i<=m;++i){
		cin>>e[i].x>>e[i].y>>e[i].z;
	}
	sort(e+1,e+m+1);
	for(i=1;i<=m;++i){
		int x=gfa(e[i].x),y=gfa(e[i].y);
		if(x!=y){
			g[x]=y;a[y]+=a[x];
			if(a[y]>=e[i].z)nw+=rr[y]+rr[x]+1,rr[y]=0;else rr[y]+=rr[x]+1;
		}else{
			if(a[y]>=e[i].z)++nw;
				else ++rr[y];
		}
		ans=max(ans,nw);
	}
	cout<<m-ans<<endl;
	return 0;
}