#include <cstdio>
#include <algorithm>
#include <iostream>
#define MN 101000

int fa[MN];
long long v[MN];
bool used[MN], ok[MN], del[MN];
int h[MN], nxt[2 * MN], to[2 * MN], K = 1;

void ins(int u, int v) {nxt[++K] = h[u]; h[u] = K; to[K] = v;}

struct xxx{int x, y, c;} e[MN];

int Find(int x) {return fa[x] == x ? x : fa[x] = Find(fa[x]);}

bool cmp(xxx a, xxx b) {return a.c < b.c;}

void dfs(int x, int now)
{
	if(used[x]) return; 
	used[x] = 1;
	for(int i = h[x]; i; i = nxt[i])
	{
		if(i / 2 > now) continue;
		ok[i >> 1] = 1;
		dfs(to[i], now);
	}
}

int main()
{
	int n, m; scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i++) scanf("%lld", &v[i]), fa[i] = i;
	for(int i = 1; i <= m; i++) scanf("%d%d%d", &e[i].x, &e[i].y, &e[i].c);
	std::sort(e + 1, e + m + 1, cmp);
	for(int i = 1; i <= m; i++)
	{
		int X = Find(e[i].x), Y = Find(e[i].y);
		ins(e[i].x, e[i].y); ins(e[i].y, e[i].x);
		if(X != Y) fa[X] = Y, v[Y] += v[X];
		if(v[Y] < e[i].c) del[i] = 1;
	}
	int ans = 0;
	for(int i = m; i >= 1; i--)
	{
		if(del[i] && !ok[i]) ans++;
		if(!del[i] && !ok[i]) dfs(e[i].x, i);
	}
	printf("%d\n", ans);
}