#include<bits/stdc++.h>

#define fec(i, x, y) (int i = head[x], y = g[i].to; i; i = g[i].ne, y = g[i].to)
#define dbg(...) fprintf(stderr, __VA_ARGS__)
#define File(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)
#define fi first
#define se second
#define pb push_back

template<typename A, typename B> inline char SMAX(A &a, const B &b) {return a < b ? a = b , 1 : 0;}
template<typename A, typename B> inline char SMIN(A &a, const B &b) {return b < a ? a = b , 1 : 0;}

typedef long long ll; typedef unsigned long long ull; typedef std::pair<int, int> pii;

template<typename I>
inline void read(I &x) {
	int f = 0, c;
	while (!isdigit(c = getchar())) c == '-' ? f = 1 : 0;
	x = c & 15;
	while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + (c & 15);
	f ? x = -x : 0;
}

const int N = 1e5 + 7;

int n, m, w[N], ans;
struct Edge{int x, y, z;} g[N];

int fa[N], num[N];
ll sum[N];
inline int Find(int x) {return fa[x] == x ? x : fa[x] = Find(fa[x]);}
inline void Union(int x, int y) {
	fa[y = Find(y)] = x = Find(x);
	num[x] += num[y], num[y] = 0;
	sum[x] += sum[y], sum[y] = 0;
}

int main() {
	#ifdef hzhkk
	freopen("hkk.in", "r", stdin);
	#endif
	read(n), read(m);
	for (int i = 1; i <= n; ++i) read(w[i]), fa[i] = i, sum[i] = w[i];
	for (int i = 1; i <= m; ++i) read(g[i].x), read(g[i].y), read(g[i].z);
	std::sort(g + 1, g + m +1, [](const Edge &a, const Edge &b){return a.z < b.z;});
	for (int i = 1; i <= m; ++i) {
		int x = Find(g[i].x), y = Find(g[i].y), z = g[i].z;
		if (Find(x) != Find(y)) Union(x, y);
		++num[x];
		if (sum[x] >= z) ans += num[x], num[x] = 0;
	}
	printf("%d\n", m - ans);
}