#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
#define SIZE 200000
typedef long long ll;
class unionfind
{
public:
	int par[SIZE];
	int ran[SIZE];
	ll ren[SIZE];
	vector<int>ko[SIZE];
	bool isact[SIZE];
	int st[SIZE];
	void init()
	{
		for (int i = 0; i < SIZE; i++)
		{
			par[i] = i;
		}
	}
	int find(int a)
	{
		if (a == par[a])return a;
		else return find(par[a]);
	}
	int actfind(int a)
	{
		if (a == par[a] || !isact[a])return a;
		else return actfind(par[a]);
	}
	void unite(int a, int b)
	{
		a = find(a);
		b = find(b);
		if (a == b)return;
		if (ran[a]>ran[b])
		{
			par[b] = a;
			ren[a] += ren[b];
			ko[a].push_back(b);
		}
		else
		{
			par[a] = b;
			ren[b] += ren[a];
			ko[b].push_back(a);
		}
		if (ran[a] == ran[b])ran[b]++;
	}
	void activate(int a)
	{
		for (int i = st[a]; i < ko[a].size(); i++)
		{
			if (isact[ko[a][i]])continue;
			activate(ko[a][i]);
			isact[ko[a][i]] = true;
		}
		st[a] = ko[a].size();
	}
};
unionfind uf;
typedef pair<ll, ll>pii;
typedef pair<ll, pii>pi3;
ll wei[202020];
int dat[202020];
ll sum[202020];
int main()
{
	int num, way;
	scanf("%d%d", &num, &way);
	uf.init();
	for (int i = 0; i < num; i++)scanf("%lld", &uf.ren[i]), wei[i] = uf.ren[i];
	vector<pi3>v;
	for (int i = 0; i < way; i++)
	{
		int za, zb, zc;
		scanf("%d%d%d", &za, &zb, &zc);
		za--, zb--;
		v.push_back(make_pair(zc, make_pair(za, zb)));
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < v.size(); i++)
	{
		int s = v[i].second.first, t = v[i].second.second;
		ll d = v[i].first;
		if (uf.find(s) == uf.find(t))continue;
		uf.unite(s, t);
		if (uf.ren[uf.find(s)] >= d)uf.activate(uf.find(s));
	}
	for (int i = 0; i < num; i++)dat[i] = uf.actfind(i), sum[uf.actfind(i)] += wei[i];
	int r = 0;
	for (int i = 0; i < v.size(); i++)
	{
		int s = v[i].second.first, t = v[i].second.second;
		ll d = v[i].first;
		if (dat[s] != dat[t] || sum[dat[s]] < d)r++;
	}
	printf("%d\n", r);
}