#include <bits/stdc++.h>
using namespace std;

const int N = 100005;

int n, m;
int par[N];
long long a[N];
long long w[N];
bool visit[N];
bool good[N];
vector<pair<int,int>> g[N];
int cnt;

struct edge {
	int from, to, id;
	edge(int from = 0, int to = 0,int id = 0) : from(from), to(to), id(id) {}
	bool operator < (const edge &e) const {
		return w[id] < w[e.id];
	}
};

vector<edge> eds;

int anc(int u) {
	if (par[u] == u) {
		return u;
	} else {
		return par[u] = anc(par[u]);
	}
}

void join(int u,int v) {
	u = anc(u), v = anc(v);
	if (u ^ v) {
		par[v] = u;
		a[u] += a[v];
	}
}

void dfs(int u,long long lim) {
	for (auto e : g[u]) {
		int v = e.first;
		int id = e.second;
		if (visit[id]) {
			continue;
		} else if (w[id] <= lim) {
			++cnt;
			visit[id] = true;
			dfs(v, lim);
		}
	}
}

int main() {
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; ++i) {
		scanf("%lld", a + i);
		par[i] = i;
	}
	for (int i = 0; i < m; ++i) {
		int u, v;
		scanf("%d %d %lld", &u, &v, w + i);
		g[u].push_back(make_pair(v, i));
		g[v].push_back(make_pair(u, i));
		eds.push_back(edge(u, v, i));
	}
	sort(eds.begin(), eds.end());
	int l = 0;
	while (l < m) {
		int r = l;
		while (r + 1 < m && w[eds[r + 1].id] == w[eds[r].id]) {
			++r;
		}
		for (int i = l; i <= r; ++i) {
			join(eds[i].from, eds[i].to);
		}
		for (int i = l; i <= r; ++i) {
			good[i] = w[eds[i].id] <= a[anc(eds[i].from)];
		}
		l = r + 1;
	}
	for (int i = eds.size() - 1; ~i; --i) {
		if (visit[eds[i].id]) {
			continue;
		} else if (good[i]) {
			dfs(eds[i].from, w[eds[i].id]);
		}
	}
	printf("%d\n", m - cnt);
}