/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e5 + 10;

struct edge {
	int a, b; ll y;
	bool operator<(const edge &o) const {
		return y < o.y;
	}
};

edge e[N];
ll x[N], wt[N];
int sz[N], parent[N];
priority_queue<ll, vector<ll>, greater<ll>> pq[N];

int get_root(int u);
void merge(int u, int v, ll w);
void clear_pq(int i);

int main() {
	fast_cin();
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		cin >> x[i];
		wt[i] = x[i];
		sz[i] = 1;
		parent[i] = i;
	}
	for (int i = 1; i <= m; ++i) {
		cin >> e[i].a >> e[i].b >> e[i].y;
	}
	sort(e + 1, e + 1 + m);
	for (int i = 1; i <= m; ++i) {
		merge(e[i].a, e[i].b, e[i].y);
	}
	cout << pq[get_root(1)].size() << endl;
}

int get_root(int u) {
	if (parent[u] != u) {
		parent[u] = get_root(parent[u]);
	}
	return parent[u];
}

void merge(int u, int v, ll w) {
	u = get_root(u);
	v = get_root(v);
	if (u == v) {
		if (w > wt[u]) {
			pq[u].push(w);
		} else {
			clear_pq(u);
		}
		return;
	}
	if (sz[u] < sz[v]) {
		swap(u, v);
	}
	wt[u] += wt[v];
	sz[u] += sz[v];
	parent[v] = u;
	if (w > wt[u]) {
		while (!pq[v].empty()) {
			pq[u].push(pq[v].top());
			pq[v].pop();
		}
		pq[u].push(w);
	} else {
		clear_pq(u);
		clear_pq(v);
	}
}

void clear_pq(int i) {
	while (!pq[i].empty()) {
		pq[i].pop();
	}
}