#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN = 100005;
struct ii {
	ll a, b, c;
	bool operator < (ii o) const {
		return a < o.a;
	}
};

ll N, M, poin[MAXN], par[MAXN], sum[MAXN], cnt[MAXN];
ii edge[MAXN];

ll find(ll x) {
	return par[x] == x? x: par[x] = find(par[x]);
}

void merge(ll x, ll y) {
	x = find(x), y = find(y);
	if (x == y) return;
	par[x] = y;
	sum[y] += sum[x];
	cnt[y] += cnt[x];
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	
	cin >> N >> M;
	for (ll i = 1; i <= N; i++) cin >> poin[i];
	for (ll i = 0; i < M; i++) {
		ll x, y, z;
		cin >> x >> y >> z;
		edge[i] = {z, x, y};
	}
	sort(edge, edge+M);
	
	for (int i = 1; i <= N; i++) {
		par[i] = i;
		sum[i] = poin[i];
	}
	ll ans = M;
	for (int i = 0; i < M; i++) {
		int x = find(edge[i].b), y = find(edge[i].c);
		if (x == y) {
			cnt[x]++;
			if (edge[i].a <= sum[x]) {
				ans -= cnt[x];
				cnt[x] = 0;
			}
		} else {
			merge(x, y);
			cnt[y]++;
			if (edge[i].a <= sum[y]) {
				ans -= cnt[y];
				cnt[y] = 0;
			}
		}
	}
	cout << ans << "\n";
}
