#include <bits/stdc++.h>
#define PII pair<int, int>
#define LL long long
using namespace std;
const int MAXN = 100005;

struct Edge {
	int a, b, w;
	bool operator < (const Edge &e) const {
		return w < e.w;
	}
};

struct DSU {
	int N, pa[MAXN], sz[MAXN];
	LL sum[MAXN];
	vector<int> who[MAXN];
	
	void init(int _N, int *x) {
		N = _N;
		for (int i = 1; i <= N; i++) {
			pa[i] = i;
			sz[i] = 1;
			sum[i] = x[i];
		}
	}
	
	int find(int x) {
		return x == pa[x] ? x : find(pa[x]);
	}
	
	void merge(int x, int y) {
		x = find(x);
		y = find(y);
		if (sz[x] < sz[y]) swap(x, y);
		if (x == y) {
			who[x].push_back(-1);
		}
		else {
			who[x].push_back(y);
			sum[x] += sum[y];
			sz[x] += sz[y];
			pa[y] = x;
		}
//		cout << "AFTER " << x << " " << sum[x] << '\n';
	}
	
	void undo(int x) {
		x = find(x);
		if (who[x].back() != -1) {
			int y = who[x].back();
			pa[y] = y;
			sum[x] -= sum[y];
			sz[x] -= sz[y];
		}
		who[x].pop_back();
	}
} dsu;

int N, M, x[MAXN];
Edge es[MAXN];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);

	cin >> N >> M;
	for (int i = 1; i <= N; i++) {
		cin >> x[i];
	}
	for (int i = 0; i < M; i++) {
		int a, b, w;
		cin >> a >> b >> w;
		es[i] = {a, b, w}; 
	}
	
	dsu.init(N, x);
	sort(es, es + M);
	for (int i = 0; i < M; i++) {
		dsu.merge(es[i].a, es[i].b);
	}
	
	int ans = 0;
	for (int i = M - 1; i >= 0; i--) {
		int root = dsu.find(es[i].a);
		if (dsu.sum[root] < es[i].w) {
			ans++;
//			cout << "UNDO " << es[i].a << " " << es[i].b << " " << es[i].w << " due to " << root << " " << dsu.sum[root] << "\n";
			dsu.undo(root);
		}
	}

	cout << ans << "\n";

	return 0;
}