#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int MAXN = 120000;

int n, m;

int p[MAXN];

int ass[MAXN];
ll s[MAXN];
vector<tuple<ll, int, int>> ed;

int get(int a) {
	if (p[a] == a)
		return a;
	return p[a] = get(p[a]);
}

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		p[i] = i;
		cin >> s[i];
		ass[i] = 0;
	}
	for (int i = 0; i < m; ++i) {
		int a, b;
		ll y;
		cin >> a >> b >> y;
		--a, --b;
		ed.emplace_back(y, a, b);
	}
	sort(ALL(ed));
	for (auto e: ed) {
		int a, b;
		ll y;
		tie(y, a, b) = e;
		a = get(a), b = get(b);
		if (a == b) {
			if (s[a] < y)
				++ass[a];
		}
		else {
			p[a] = b;
			s[b] += s[a];
			ass[b] += ass[a];
			if (s[b] >= y)
				ass[b] = 0;
			else
				ass[b] += 1;
		}
	}
	for (int i = 0; i < n; ++i) {
		if (p[i] == i) {
			cout << ass[i] << "\n";
			return 0;
		}
	}
	return 0;
}


