#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 100100;
struct edges
{
	int to, next;
	long long len;
}edge[maxn << 1];
int point[maxn] = {0}, te = 1;
void add(int a, int b, int c)
{
	te ++;
	edge[te].to = b;
	edge[te].next = point[a];
	edge[te].len = c;
	point[a] = te;
}
int n, m;
long long v[maxn];
struct E2
{
	int a, b;
	long long c;
	bool operator<(const E2 &a) const
	{
		return c < a.c;
	}
}ea[maxn];
int par[maxn];
long long sum[maxn] = {0};
bool con[maxn] = {0};
int getr(int x)
{
	if(x == par[x])
		return x;
	return par[x] = getr(par[x]);
}
void merge(int ra, int rb)
{
	if(ra == rb)
		return ;
	par[ra] = rb;
	sum[rb] += sum[ra];
}
bool flag[maxn] = {0};
void dfs(int now, long long mx)
{
	for(int e = point[now]; e; e = edge[e].next)
		if(!flag[e / 2] && edge[e].len <= mx)
		{
			//cout << now << " " << edge[e].to << " " << edge[e].len << endl;
			flag[e / 2] = 1;
			dfs(edge[e].to, mx);
		}
}
int main()
{
	std::ios::sync_with_stdio(false);
	cin >> n >> m;
	for(int i = 1; i <= n; i ++)
		cin >> v[i];
	for(int i = 1; i <= m; i ++)
		cin >> ea[i].a >> ea[i].b >> ea[i].c;
	sort(ea + 1, ea + m + 1);
	for(int i = 1; i <= n; i ++)
	{
		par[i] = i;
		sum[i] = v[i];
	}
	for(int i = 1; i <= m; i ++)
	{
		int ra = getr(ea[i].a), rb = getr(ea[i].b);
		merge(ra, rb);
		if(ea[i].c <= sum[rb])
		{
			con[i] = 1;
			//cout << i << " " << ea[i].a << " " << ea[i].b << " " << ea[i].c << endl;
		}
		add(ea[i].a, ea[i].b, ea[i].c);
		add(ea[i].b, ea[i].a, ea[i].c);
	}
	for(int i = m; i >= 1; i --)
		if(!flag[i] && con[i])
		{
			//cout << i << " " << ea[i].a << " " << ea[i].b << " " << ea[i].c << " ------------------------- " << endl;
			dfs(ea[i].a, ea[i].c);
		}
	int ans = 0;
	for(int i = 1; i <= m; i ++)
		if(!flag[i] && !con[i])
			ans ++;
	cout << ans << endl;
	return 0;
}