#include<cstdio>
#include<algorithm>
#define Rint register int
using namespace std;
typedef long long LL;
const int N = 100003;
int n, m, cnt[N], fa[N], ans;
LL sum[N];
struct Edge {
	int u, v, w;
	inline bool operator < (const Edge &o) const {return w < o.w;}
} e[N];
inline int getfa(int x){
	return x == fa[x] ? x : fa[x] = getfa(fa[x]);
}
int main(){
	scanf("%d%d", &n, &m);
	for(Rint i = 1;i <= n;i ++){
		scanf("%lld", sum + i);
		fa[i] = i;
	}
	for(Rint i = 1;i <= m;i ++) scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
	sort(e + 1, e + m + 1);
	for(Rint i = 1;i <= m;i ++){
		int fa1 = getfa(e[i].u), fa2 = getfa(e[i].v);
		if(fa1 == fa2) ++ cnt[fa1];
		else {
			cnt[fa1] += cnt[fa2] + 1;
			sum[fa1] += sum[fa2];
			cnt[fa2] = sum[fa2] = 0;
			fa[fa2] = fa1;
		}
		if(sum[fa1] >= e[i].w){
			ans += cnt[fa1];
			cnt[fa1] = 0;
		}
	}
	printf("%d\n", m - ans);
}