#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using T = tuple<int, int, int>;
const int MX = 100005;
int n, m, p[MX], d[MX], a, b, c;
long long w[MX];
T tp[MX];
int find(int x){return (p[x] < 0 ? x : p[x] = find(p[x]));}
void uni(int x, int y, int z){
	x = find(x); y = find(y);
	if(x != y){
		if(p[x] > p[y]) swap(x, y);
		p[x] += p[y];
		w[x] += w[y];
		d[x] += d[y];
		p[y] = x;
	}
	if(z <= w[x]) d[x] = 0;
	else d[x]++;
}
int main(){
	scanf("%d%d", &n, &m);
	rep(i,n){
		scanf("%lld", w+i);
		p[i] = -1;
	}
	rep(i,m){
		scanf("%d%d%d", &a, &b, &c);
		tp[i] = T(c,a-1,b-1);
	}
	sort(tp, tp+m);
	rep(i,m){
		tie(c,a,b) = tp[i];
		uni(a,b,c);
	}
	printf("%d\n", d[find(a)]);
}