#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;

const int MAX_N = (1 << 18);

long long N, M, X[MAX_N], A[MAX_N], B[MAX_N], Y[MAX_N], col[MAX_N];
long long group[MAX_N], s[MAX_N]; vector<int>G[MAX_N]; vector<pair<int, int>> I[MAX_N];
vector<tuple<long long, long long, long long>>tup;

vector<pair<long long, long long>>vec;

void init() {
	for (int i = 1; i <= N; i++) { group[i] = i; s[i] = X[i]; G[i].push_back(i); }
}
void unite(int u, int v, long long w) {
	u = group[u]; v = group[v];
	if (u == v) return;

	if (G[u].size() < G[v].size()) swap(u, v);

	for (int i = 0; i < G[v].size(); i++) {
		G[u].push_back(G[v][i]); group[G[v][i]] = u;
	}
	G[v].clear();
	s[u] += s[v]; s[v] = 0;

	if (s[u] >= w) vec.push_back(make_pair(u, s[u]));
}

void dfs(int pos, long long weight) {
	if (col[pos] != -1) return;
	col[pos] = weight;
	for (int i = 0; i < I[pos].size(); i++) {
		if (I[pos][i].second > weight) continue;
		dfs(I[pos][i].first, weight);
	}
}

int main() {
	cin >> N >> M;
	for (int i = 1; i <= N; i++) cin >> X[i];
	for (int i = 0; i < M; i++) {
		cin >> A[i] >> B[i] >> Y[i];
		I[A[i]].push_back(make_pair(B[i], Y[i]));
		I[B[i]].push_back(make_pair(A[i], Y[i]));
		tup.push_back(make_tuple(Y[i], A[i], B[i]));
	}
	sort(tup.begin(), tup.end());
	init();

	for (int i = 0; i < tup.size(); i++) {
		unite(get<1>(tup[i]), get<2>(tup[i]), get<0>(tup[i]));
	}

	for (int i = 1; i <= N; i++) col[i] = -1;
	for (int i = vec.size() - 1; i >= 0; i--) {
		dfs(vec[i].first, vec[i].second);
	}

	int cnt = 0;
	for (int i = 0; i < M; i++) {
		if (min(col[A[i]], col[B[i]]) >= Y[i]) cnt++;
	}
	cout << M - cnt << endl;
	return 0;
}