#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, M, p[100000], s[100000], c;
ll w[100000];
tuple<int, int, int>e[100000];

int par(int x) {
	if (p[x] == x)return x;
	else return par(p[x]);
}

void uni(int x, int y) {
	x = par(x);
	y = par(y);
	if (x == y)return;
	if (s[x] >= s[y]) {
		s[x] += s[y];
		w[x] += w[y];
		p[y] = x;
	}
	else {
		s[y] += s[x];
		w[y] += w[x];
		p[x] = y;
	}
}

int main() {
	cin >> N >> M;
	for (int i = 0; i < N; ++i) {
		cin >> w[i];
		s[i] = 1;
		p[i] = i;
	}
	for (int i = 0; i < M; ++i) {
		cin >> get<1>(e[i]) >> get<2>(e[i]) >> get<0>(e[i]);
		--get<1>(e[i]);
		--get<2>(e[i]);
	}
	sort(e, e + M);
	for (int i = 0; i < M; ++i) {
		get<1>(e[i]) = par(get<1>(e[i]));
		get<2>(e[i]) = par(get<2>(e[i]));
		uni(get<1>(e[i]), get<2>(e[i]));
	}
	for (int i = M - 1; i >= 0; --i) {
		if (w[par(get<1>(e[i]))] < get<0>(e[i])) {
			++c;
			int X, Y;
			X = get<1>(e[i]);
			Y = get<2>(e[i]);
			if (s[X] > s[Y])swap(X, Y);
			if (X != Y&&p[X] == Y) {
				p[X] = X;
				while(true) {
					w[Y] -= w[X];
					if (Y == p[Y])break;
					Y = p[Y];
				}
			}
		}
	}
	cout << c << endl;
}
