#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 1e9 + 7;

int n, m;
int wei[200005];
pair<int, PII> E[100005];
int hv[100005];

int tot;
int par[200005], val[200005];
vector<int> T[200005];
void init()
{
	rep1(i, n) par[i] = i;
	tot = n;
}

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

int unite(int u, int v, int w)
{
	u = root(u);
	v = root(v); 
	if(u == v) return 0;
	
	tot ++;
	T[tot].clear();
	par[tot] = tot;
	val[tot] = w;
	
	par[u] = par[v] = tot;
	T[tot].push_back(u);
	T[tot].push_back(v);
	return tot;
}

int ans;
LL sz[200005];
bool gg[200005];

void dfs0(int v)
{
	sz[v] = wei[v];
	rep(i, T[v].size()) {
		dfs0(T[v][i]);
		sz[v] += sz[T[v][i]];
	}
}

void dfs1(int v)
{
	if(sz[v] < val[v]) {
		gg[v] = true;
		ans ++;
		rep(i, T[v].size()) dfs1(T[v][i]);
	}
}

int main()
{
	scanf("%d%d", &n, &m);
	rep1(i, n) scanf("%d", &wei[i]);
	rep(i, m) scanf("%d%d%d", &E[i].second.first, &E[i].second.second, &E[i].first);
	sort(E, E + m);
	
	init();
	rep(i, m) hv[i] = unite(E[i].second.first, E[i].second.second, E[i].first);
	
	rep1(i, tot) if(par[i] == i) {
		dfs0(i);
		dfs1(i);
	}
	
	init();
	rep(i, m) if(hv[i] && !gg[hv[i]]) unite(E[i].second.first, E[i].second.second, E[i].first);
	rep1(i, tot) if(par[i] == i) dfs0(i);
	
	rep(i, m) if(!hv[i]) {
		int u = root(E[i].second.first), v = root(E[i].second.second);
		if(u != v || sz[u] < E[i].first) ans ++;
	}
	printf("%d\n", ans);
	return 0;
}