#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<list>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int n, m;
ll X[100005];

//-----UnionFind--------
vector<int> par, rk, cn;

void initUnion(int n)
{
	for (int i = 0;i < n;i++) {
		par.push_back(i);
		rk.push_back(1);
		cn.push_back(0);
	}
}

int root(int x) {
	if (par[x] == x) return x;
	return par[x] = root(par[x]);
}

void unite(int x, int y) {
	int rx = root(x);
	int ry = root(y);
	if (rx == ry) return;

	if (rk[ry] < rk[rx]) swap(rx, ry);
	X[ry] += X[rx];
	rk[ry] += rk[rx];
	cn[ry] += cn[rx];
	par[rx] = ry;
}

bool same(int x, int y) {
	int rx = root(x);
	int ry = root(y);
	return rx == ry;
}
//-----UnionFind--------

class edge {
public:
	int u;
	int v;
	ll w;
};

bool comp(edge v, edge u)
{
	return v.w < u.w;
}

int main()
{
	cin >> n >> m;
	vector<edge> e(m);
	int u, v, w;

	for (int i = 0;i < n;i++) cin >> X[i];
	for (int i = 0;i < m;i++) {
		cin >> u >> v >> w;
		u--;
		v--;
		e[i].u = u;
		e[i].v = v;
		e[i].w = w;
	}

	sort(e.begin(), e.end(), comp);

	int ans = m;
	initUnion(n);

	for (int i = 0;i < m;i++) {
		w = e[i].w;
		v = e[i].v;
		u = e[i].u;

		if (!same(u, v)) {
			int Ru = root(u);
			int Rv = root(v);
			unite(u, v);
		}

		int Ru = root(u);
		cn[Ru]++;

		if (X[Ru] >= w) {
			ans -= cn[Ru];
			cn[Ru] = 0;
		}
	}

	cout << ans << endl;

	return 0;
}
