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

#define N 100010
#define MP make_pair
typedef long long LL;

int fa[N], rk[N], pa[N], vis[N];
LL w[N];

struct edge
{
	int x, y, z;
	bool operator < (const edge &t)const
	{
		return z < t.z;
	}
}e[N];

int find(int x)
{
	while (fa[x] ^ x) x = fa[x];
	return x;
}

void merge(int x, int y, int i)
{
	x = find(x), y = find(y);
	if (x == y) return;
	
	vis[i] = 1;
	if (rk[x] < rk[y]) swap(x, y);
	fa[y] = x; w[x] += w[y];
	if (rk[x] == rk[y]) rk[x]++;
	pa[i] = y;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; ++i)
		scanf("%lld", &w[i]), fa[i] = i;
	for (int i = 1; i <= m; ++i)
		scanf("%d %d %d", &e[i].x, &e[i].y, &e[i].z);
	sort(e + 1, e + m + 1);
	
	for (int i = 1; i <= m; ++i)
	{
		merge(e[i].x, e[i].y, i);
	}
	int ans = 0;
	for (int i = m; i >= 1; --i)
	{
		int s = find(e[i].x);
		if (e[i].z > w[s])
		{
			++ans;
			if (vis[i]) 
			{
				w[s] -= w[pa[i]];
				fa[pa[i]] = pa[i];
			}
		}
	}
    cout << ans << endl;
	return 0;	
}