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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl

const int MN = 100010;

class unionfind {
public:
	vector<int> par;
	vector<ll> sum;
	vector<int> cand;

	void init(int n, vector<ll> X) {
		par.resize(n);
		sum.resize(n);
		cand.resize(n);

		for (int i = 0; i < n; i++) {
			par[i] = i;
			sum[i] = X[i];
			cand[i] = 0;
		}
	}

	int find(int x) {
		if (par[x] == x) return x;
		else {
			int p = find(par[x]);
			if (par[x] != p) {
				cand[p] += cand[par[x]];
				sum[p] += sum[par[x]];
			}
			return par[x] = p;
		}
	}

	bool unite(int x, int y) {
		x = find(x);
		y = find(y);

		if (x == y) return true;
		cand[x] += cand[y];
		sum[x] += sum[y];
		par[y] = x; 
		cand[y] = 0; sum[y] = 0;
	}

	bool same(int x, int y) { return (find(x) == find(y)); }
} uf;

int N, M;
vi g[MN];

int main() {
	cin >> N >> M;

	vector<ll> X(N);
	rep(i, N) cin >> X[i];
	uf.init(N, X);

	vector<pair<ll, pii>> es;

	rep(i, M) {
		int a, b; ll c; cin >> a >> b >> c; --a; --b;
		g[a].pb(b); g[b].pb(a);
		es.eb(c, mp(a, b));
	}

	sort(ALL(es));

	int ans = 0;

	rep(i, M) {
		int a = es[i].se.fi, b = es[i].se.se;
		ll c = es[i].fi;

		if (uf.same(a, b)) {
			int p = uf.find(a);
			if (uf.sum[p] >= c) {
				++ans;
			} else {
				++uf.cand[p];
			}
		} else {
			int p1 = uf.find(a), p2 = uf.find(b);
			if (uf.sum[p1] + uf.sum[p2] >= c) {
				ans += uf.cand[p1];
				ans += uf.cand[p2];
				++ans;
				uf.cand[p1] = uf.cand[p2] = 0;
				uf.unite(a, b);
			} else {
				uf.unite(a, b);
				++uf.cand[uf.find(a)];
			}
		}
	}

	cout << M - ans << endl;

	return 0;
}