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

int par[100010];
long long tot[100010];

stack <pair <int, int>> s;
stack <pair <int, long long>> t;

int root(int x) {
	if(x == par[x]) return par[x];
	int val = root(par[x]);
	s.emplace(x, par[x]);
	return par[x] = val;
}

void join(int x, int y) {
	x = root(x);
	y = root(y);
	if(x != y) {
		s.emplace(x, par[x]);
		t.emplace(y, tot[y]);
		par[x] = y;
		tot[y] += tot[x];
	}
}

int c[100010];
int l[100010], r[100010], w[100010];
int ans;
int n, m;

bool cmp(int p, int q) {
	return w[p] < w[q];
}
void solve() {
	for(int i = 1; i <= n; i++) {
		par[i] = i;
		tot[i] = c[i];
	}
	vector <int> can;
	for(int i = 1; i <= m; i++) {
		can.emplace_back(i);
	}
	sort(can.begin(), can.end(), cmp);

	stack <int> tm1, tm2;
	for(auto i : can) {
		tm1.push(s.size());
		tm2.push(t.size());
		join(l[i], r[i]);
	}
	reverse(can.begin(), can.end());
	for(auto i : can) {
		if(tot[root(l[i])] < w[i]) {
			while(s.size() > tm1.top()) {
				par[s.top().first] = s.top().second;
				s.pop();
			}
			while(t.size() > tm2.top()) {
				tot[t.top().first] = t.top().second;
				t.pop();
			}
			++ans;
		} else {
			while(s.size() > tm1.top()) {
				s.pop();
			}
			while(t.size() > tm2.top()) {
				t.pop();
			}
		}
		tm1.pop();
		tm2.pop();
	}
}

int main(int argc, char const *argv[])
{
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i++) {
		scanf("%d", &c[i]);
	}
	for(int i = 1; i <= m; i++) {
		scanf("%d %d %d", &l[i], &r[i], &w[i]);
	}
	solve();
	printf("%d\n", ans);
	return 0;
}