#include<bits/stdc++.h>
#define N 200005
using namespace std;
typedef long long LL;
int a[N],f[N],rk[N],n,m,ans;
LL g[N];
int A[N],B[N],C[N],cut[N];
struct edge{
	int x,y,z;
	int operator < (const edge &b)const{
		return z<b.z;
	}
}e[N];
int get(int u){for (;f[u]!=u;u=f[u]);return u;}
void Union(int tot,int u,int v){
	if (rk[u]<rk[v]) swap(u,v);
	A[tot]=u;B[tot]=v;C[tot]=rk[u]==rk[v];
	f[v]=u;rk[u]+=C[tot];g[u]+=g[v];
}
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for (int i=1;i<=m;i++)
		scanf("%d%d%d",&e[i].x,&e[i].y,&e[i].z);
	sort(e+1,e+m+1);
	for (int i=1;i<=n;i++) f[i]=i,g[i]=a[i],rk[i]=0;
	for (int i=1;i<=m;i++){
		int u=get(e[i].x),v=get(e[i].y);
		if (u==v) cut[i]=0;else cut[i]=1,Union(i,u,v);
	}
	for (int i=m;i;i--)
		if (cut[i]){
			if (g[get(e[i].x)]>=e[i].z) continue;
			int u=A[i],v=B[i],w=C[i];
			f[v]=v;rk[u]-=w;g[u]-=g[v];ans++;
			int t1=get(e[i].x),t2=get(e[i].y);
			//assert(t1==u&&t2==v||t1==v&&t2==u);
		}
		else
			ans+=g[get(e[i].x)]<e[i].z;
	printf("%d\n",ans);
}