#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<endl
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const int INF = 1e9;
int dx[4] = { 0,0,-1,1 }, dy[4] = { 1,-1,0,0 };

int W[MAX];//連結成分の頂点の重みの和
int siz[MAX];//錬結成分のサイズ
int par[MAX];//親
int Rank[MAX];//木の深さ

//n要素で初期化
void init(int n) {
	REP(i, n) {
		par[i] = i;
		Rank[i] = 0;
		siz[i] = 1;
	}
}

//木の根を求める
int find(int x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);//経路圧縮(根に直接つなぎなおす)もしつつ
	}
}

//xとyの属する集合を併合
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	//低いほうを高いほうにつなげる(効率化)
	if (Rank[x] < Rank[y]) {
		par[x] = y;
		siz[x] += siz[y];
		siz[y] = siz[x];
		W[x] = W[y] = W[x] + W[y];
	}
	else {
		siz[y] += siz[x];
		siz[x] = siz[y];
		W[x] = W[y] = W[x] + W[y];
		par[y] = x;
		if (Rank[x] == Rank[y])Rank[x]++;
	}
}

//xとyが同じ集合に属するか否か
bool same(int x, int y) {
	return find(x) == find(y);
}

int X[200020];
struct edge {
	int from, to, cost, index;
};
bool comp(const edge &e1, const edge &e2) {
	return e1.cost < e2.cost;
}
vector<edge>G[100010];
vector<edge>es;
ll ans = 0;
bool used[100010];
void dfs(int n,int w) {
	//pe(n); print(w);
	for (auto e : G[n]) {
		if (e.cost > w || used[e.index])continue;
		ans++; used[e.index] = true;
		dfs(e.to, w);
	}
}
void solve() {
	int N, M; cin >> N >> M;
	//es.resize(M);
	REP(i, N)cin >> X[i];
	REP(i, M) {
		int u, v, c; cin >> u >> v >> c; u--, v--;
		es.push_back({ u,v,c,i });
		G[u].push_back({ u,v,c,i });
		G[v].push_back({ v,u,c,i });
	}
	sort(all(es), comp);
	init(N);
	REP(i, N) {
		W[i] = X[i];
	}
	vector<edge>use;
	REP(i, M) {
		edge e = es[i];
		unite(e.from, e.to);
		if (W[find(e.from)] >= e.cost) {
			//pe(e.from); print(e.to);
			use.push_back(e);
		}
	}
	VREVERSE(use);
	REP(i,use.size()){
		dfs(use[i].from, use[i].cost);
	}
	print(M - ans);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q;cin>>q;
	//while(q--)
	solve();
}




Measured memory_bytes: 29932