#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 100000;
int n, a[maxn + 10], fa[maxn + 10], m, ans;
ll totw[maxn + 10];
bool vis[maxn + 10];
struct edge {
	int l, r, w;
	bool operator < (const edge &t) const {
		return w < t.w;
	}
}b[maxn + 10];
bool is[maxn + 10];

struct edge2 {
	int to, w;
};
vector<edge2> g[maxn + 10];

int getf(int p) {
	return fa[p] == p ? p : fa[p] = getf(fa[p]);
}

void dfs(int p, int w) {
	vis[p] = 1;
	for (int i = 0; i < (int)g[p].size(); ++i) {
		edge2 e = g[p][i];
		if (!vis[e.to] && e.w <= w) dfs(e.to, w);
	}
}

int main() {
	scanf("%d%d", &n, &m); ans = m;
	for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	for (int i = 1; i <= m; ++i) {
		scanf("%d%d%d", &b[i].l, &b[i].r, &b[i].w);
		g[b[i].l].push_back((edge2){b[i].r, b[i].w});
		g[b[i].r].push_back((edge2){b[i].l, b[i].w});
	}
	sort(b + 1, b + m + 1);
	for (int i = 1; i <= n; ++i) {
		fa[i] = i; totw[i] = a[i];
	}
	for (int i = 1; i <= m; ++i) {
		int x = getf(b[i].l), y = getf(b[i].r);
		if (x != y) {
			fa[x] = y; totw[y] += totw[x];
		}
		if (totw[y] >= b[i].w) is[i] = 1;
	}
	for (int i = m; i >= 1; --i) {
		if (vis[b[i].l]) --ans;
		else if (is[i]) {
			--ans;
			dfs(b[i].l, b[i].w);
		}
	}
	printf("%d", ans);
}