#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 444444;
int n,m,a[N],fa[N],tot,idx[N];Vi ch[N];ll sum[N];
struct edge{
	int a,b,c;
}e[N];bool cmp(edge a, edge b){return a.c<b.c;}
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
struct qaqq{
	int f[N];ll g[N];
	void init(){
		rep(i,1,n)f[i]=i,g[i]=a[i];
	}
	int find(int x){return f[x]==x?x:f[x]=find(f[x]);}
	void merge(int u, int v){
		u=find(u);v=find(v);
		if(u!=v){f[u]=v;g[v]+=g[u];}
	}
	int query(int u, int v, int c){
		u=find(u);v=find(v);
		if(u==v&&c<=g[u])return 0;return 1;
	}
}qaq;
void dfs1(int u){
	if(u<=n)sum[u]=a[u];rep(i,0,SZ(ch[u])-1)dfs1(ch[u][i]),sum[u]+=sum[ch[u][i]];
}
void dfs(int u, bool flag){
	flag|=u>n&&sum[u]>=e[idx[u]].c;
	if(u>n&&flag)qaq.merge(e[idx[u]].a,e[idx[u]].b);
	rep(i,0,SZ(ch[u])-1)dfs(ch[u][i],flag);
}
int main() {
	read(n);read(m);
	rep(i,1,n)read(a[i]);
	rep(i,1,m)read(e[i].a),read(e[i].b),read(e[i].c);
	sort(e+1,e+m+1,cmp);
	rep(i,1,N-1)fa[i]=i;tot=n;qaq.init();
	rep(i,1,m){
		int u=find(e[i].a),v=find(e[i].b);
		if(u!=v){
			tot++;idx[tot]=i;fa[u]=tot;fa[v]=tot;
			ch[tot].pb(u);ch[tot].pb(v);
		}
	}
	int rt=find(1);dfs1(rt);dfs(rt,0);
	int res=0;
	rep(i,1,m)res+=qaq.query(e[i].a,e[i].b,e[i].c);
	cout<<res;
	return 0;
}
