#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
#define rg register
using namespace std;
typedef long long ll;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }
const int Maxn = 1e5 + 5;
int n, m, f[Maxn], num[Maxn], ans;
ll sum[Maxn];
struct str
{
	int a, b, val;
	bool operator<(str an) const
	{
		return val < an.val;
	}
} e[Maxn];
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
int main()
{
	int u, v;
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &sum[i]);
		f[i] = i;
	}
	for (int i = 1; i <= m; i++)
		scanf("%d%d%d", &e[i].a, &e[i].b, &e[i].val);
	sort(e + 1, e + m + 1);
	for (int i = 1; i <= m; i++)
	{
		u = find(e[i].a);
		v = find(e[i].b);
		if (u != v)
		{
			num[u] += num[v];
			sum[u] += sum[v];
			f[v] = u;
		}
		num[u]++;
		if (sum[u] >= e[i].val)
		{
			ans += num[u];
			num[u] = 0;
		}
	}
	cout << m - ans << endl;
	return 0;
}
