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

#define ll long long
#define pb push_back

const int maxn = 1e5 + 20;

vector<int> adj[maxn];

int from[maxn] , to[maxn] , w[maxn] , ind[maxn];

int val[maxn] , par[maxn];
ll sum[maxn];

bool reval[maxn];

vector<pair<int , int> > history;

bool cmp(int a , int b)
{
	return w[a] < w[b];
}

int root(int v)
{
	return par[v] < 0? v : root(par[v]);
}

void merge(int a , int b)
{
	a = root(a) , b = root(b);
	if(a == b)
	{
		history.pb({-1 , -1});
		return;
	}

	if(-par[a] < -par[b])
		swap(a , b);

	history.pb({b , par[b]});
	par[a] += par[b];
	par[b] = a;
	sum[a] += sum[b];
	adj[a].pb(b);
}

void undo()
{
	int v = history.back().first , sz = history.back().second;
	history.pop_back();
	if(v < 0)
		return;

	int u = par[v];

	adj[u].pop_back();
	sum[u] -= sum[v];
	par[v] = sz;
	par[u] -= par[v];
}

void put(int v)
{
	reval[v] = 1;
	for(auto u : adj[v])
		put(u);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	memset(par , -1 , sizeof par);

	int n , m;
	cin >> n >> m;

	for(int i = 0; i < n; i++)
		cin >> sum[i];

	for(int i = 0; i < m; i++)
	{
		int a , b;
		cin >> a >> b >> w[i];
		a-- , b--;

		from[i] = a , to[i] = b , ind[i] = i;
	}
	
	sort(ind , ind + m , cmp);

	for(int i = 0; i < m; i++)
		merge(from[ind[i]] , to[ind[i]]);

	int res = 0;
	for(int i = m - 1; i >= 0; i--)
	{
		int k = ind[i];
		if(!reval[from[k]])
		{
			int v = root(from[k]);
			if(sum[v] >= w[k])
				put(v);
			else
				res++;
		}

		undo();
	}

	cout << res << endl;
}








