#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
int n, cur, p[N], aa[N], bb[N], w[N], at[N], lab[N], num[N];
vector <int> g[N];
long long siz[N], fath[N];
long long find (int a);
void uni (int a, int b);
pair <int, pair<int, int> > edge[N];
void dfs (int a, int b, long long c);
int main() {
	int a, b;
	cin >> a >> b;
	n = a;
	for (int i = 0; i < a; i ++)
		cin >> p[i];
	for (int i = 0; i < b; i ++) {
		cin >> aa[i] >> bb[i] >> w[i];
		aa[i] --;
		bb[i] --;
		edge[i] = make_pair (w[i], make_pair(aa[i], bb[i]));
	}
	sort (edge, edge + b);
	for (int i = 0; i < a; i ++)
		fath[i] = -p[i];
	for (int i = 0; i < a; i ++)
		at[i] = i;
	int sz = a;
	for (int i = 0; i < a; i ++)
		siz[i] = p[i];
	for (int i = 0; i < b; i ++) {
		if (find(edge[i].second.first) == find(edge[i].second.second))
			continue;
		int lf = find (edge[i].second.first);
		int rt = find (edge[i].second.second);
		g[sz].push_back(at[lf]);
		g[sz].push_back(at[rt]);
		uni (lf, rt);
		at[lf] = sz;
		siz[sz] = -fath[lf];
		if (-fath[lf] >= edge[i].first) {
			lab[sz] = 1;
		}
		sz ++;
	}
	dfs (sz - 1, -1, -1);
	int ret = b;
	for (int i = 0; i < b; i ++) {
		if (num[aa[i]] == num[bb[i]] && w[i] <= siz[aa[i]])
			ret --;
	}
	cout << ret;
	return 0;
}
long long find (int a) {
	if (fath[a] < 0)
		return a;
	return fath[a] = find(fath[a]);
}
void uni (int a, int b) {
	a = find(a);
	b = find(b);
	if (a == b)
		return ;
	fath[a] += fath[b];
	fath[b] = a;
	return ;
}
void dfs (int a, int b, long long c){
	if (a < n) {
		num[a] = b;
		if (c != -1)
			siz[a] = c;
	}
	if (b == -1 && lab[a]) {
		b = a;
		c = siz[a];
	}
	for (int i = 0; i < g[a].size(); i ++) {
		dfs (g[a][i], b, c);
	}
}