#include <bits/stdc++.h>
using namespace std;
#define int64 long long
#define mp make_pair
#define pb push_back
#define fs first
#define sc second
#define sz(a) ((int) (a).size())

const int N = (int) 1e6 + 10;
int x[N], p[N], bad[N], sum_bad, n, m, good, last = -1;
int64 sum[N];

int getp(int v) {
	return (v == p[v]) ? v : (p[v] = getp(p[v]));
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &x[i]);
		p[i] = i;
		sum[i] = x[i];
	}
	vector< pair< int, pair<int, int> > > e(m);
	for (int i = 0; i < m; ++i) {
		scanf("%d%d%d", &e[i].sc.fs, &e[i].sc.sc, &e[i].fs);
		--e[i].sc.fs, --e[i].sc.sc;
	}
	sort(e.begin(), e.end());
	for (int i = 0; i < m; ++i) {
		int u = getp(e[i].sc.fs), v = getp(e[i].sc.sc), w = e[i].fs;
		if (u != v) {
			sum[u] += sum[v], p[v] = u, bad[u] += bad[v];
			if (w <= sum[u]) {
				sum_bad -= bad[u];
				bad[u] = 0;
			} else {
				bad[u]++;
				sum_bad++;
			}
		} else {
			if (w > sum[u]) {
				bad[u]++;
				sum_bad++;
			}
		}
	}
	printf("%d\n", sum_bad);
	return 0;
}
