#include <iostream>
#include <algorithm>

using namespace std;
const int MAXN = 1e5 + 7;
#define i64 long long
struct edge {
	int A, B;
	i64 Y;
}ed[MAXN];

int N, M;
i64 X[MAXN];
int qan[MAXN];
int qanprev[MAXN];
int p[MAXN];
int zib;

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


void merge(int x, int y)
{
	x = find(x);
	y = find(y);
	p[x] = y;
	qan[y] += qan[x];
	qanprev[y] += qanprev[x];
	X[y] += X[x];
}

int main() {
	cin >> N >> M;
	for (int i = 1; i <= N; i++) {
		cin >> X[i];
		qan[i] = 1;
		p[i] = i;
	}
	for (int i = 0; i <= M; i++) {
		cin >> ed[i].A >> ed[i].B >> ed[i].Y;
	}
	sort(ed, ed + M, [&](edge &a, edge&b) {return a.Y < b.Y; });
	for (int i = 0; i <= M; i++) {
		int firp = find(ed[i].A);
		int secp = find(ed[i].B);
		if (firp != secp) {
			merge(ed[i].A, ed[i].B);
			if (ed[i].Y <= X[firp]) {
				zib -= qanprev[firp];
				qanprev[firp] = qan[firp];
				zib += qanprev[firp];
			}
		}
		else {
			int frip = find(ed[i].A);
			++qan[frip];
			if (ed[i].Y <= X[frip]) {
				++qanprev[frip];
				++zib;
			}
		}
	}
	cout << m - zib << endl;
	return 0;
}