//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimise ("ofast")
#pragma GCC optimise("unroll-loops")
#define int long long

using namespace std;

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

const int N = 100000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000000000000000;
const ll LOG = 25;

bool mark[N];
int n, m, a[N], ans, par[N], seg[2][N << 2], lazy[2][N << 2], ps[N], inv[N], inv2[N];
vector<int> com[N];
vector<int> ki[N];
struct edge{
	int v, u, w;
};
edge E[N];
bool merge(int v, int u, int id){
	v = par[v], u = par[u];
	if (v == u) return 0;
	if (com[v].size() < com[u].size()) swap(v, u);
	ki[v].pb(id);
	for (auto x:com[u]){
		com[v].pb(x);
		par[x] = v;
	}
	for (auto x:ki[u]) ki[v].pb(x);
	ki[u].clear();
	ki[u].shrink_to_fit();
	com[u].clear();
	com[u].shrink_to_fit();
	return 1;
}

bool cmp(edge x, edge y){
	return x.w < y.w;
}

void modify(int id, int ind, int x){
	if (ind == 0) seg[ind][id] = max(seg[ind][id], x), lazy[ind][id] = max(lazy[ind][id], x);
	else seg[ind][id] = min(seg[ind][id], x), lazy[ind][id] = min(lazy[ind][id], x);
}

void shift(int id, int ind){
	modify(id << 1, ind, lazy[ind][id]);
	modify(id << 1 | 1, ind, lazy[ind][id]);
	if (ind == 0) lazy[ind][id] = 0;
	else lazy[ind][id] = 2000000000;
}

void add(int id, int ind, int lq, int rq, int x, int l, int r){
	if (rq <= l || r <= lq) return;
	if (lq <= l && r <= rq){
		//cout << id << endl;
		modify(id, ind, x);
		return;
	}
	int md = (l + r) >> 1;
	shift(id, ind);
	add(id << 1, ind, lq, rq, x, l, md);
	add(id << 1 | 1, ind, lq, rq, x, md, r);
	if (ind == 0) seg[ind][id] = max(seg[ind][id << 1], seg[ind][id << 1 | 1]);
	else seg[ind][id] = min(seg[ind][id << 1], seg[ind][id << 1 | 1]);
}

int get(int id, int ind, int lq, int rq, int l, int r){
	if (rq <= l || r <= lq){
		if (ind == 0) return 0;
		return 2000000000;
	}
	if (lq <= l && r <= rq){
       // cout << lq << ' ' << rq << ' ' << seg[ind][id] << endl;
		return seg[ind][id];
	}
	shift(id, ind);
	int md = (l + r) >> 1;
	if (ind == 0){
		return max(get(id << 1, ind, lq, rq, l, md), get(id << 1 | 1, ind, lq, rq, md, r));
	}
	return min(get(id << 1, ind, lq, rq, l, md), get(id << 1 | 1, ind, lq, rq, md, r));
}

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= m; i++){
		int v, u, w;
		cin >> v >> u >> w;
		E[i].v = v;
		E[i].u = u;
		E[i].w = w;
	}
	memset(seg[1], 31, sizeof seg[1]);
	memset(lazy[1], 31, sizeof lazy[1]);
	for (int i = 1; i <= n; i++)par[i] = i, com[i].pb(i);
	sort(E + 1, E + m + 1, cmp);
	for (int i = 1; i <= m; i++){
		mark[i] = merge(E[i].v, E[i].u, i);
		//cout << E[i].w << '\n';
	}
	//cout << "YES" << endl;
	int V = par[1];
    for (int i = 0; i < com[V].size(); i++){
        ps[i + 1] = ps[i] + a[com[V][i]];
        inv2[com[V][i]] = i + 1;
     //   cout << com[V][i] << ' ';
    }
    //cout << '\n';
    for (int i = 0; i < ki[V].size(); i++){
        inv[ki[V][i]] = i + 1;
    //	cout << ki[V][i] << ' ';
	}
	//cout << '\n';
    add(1, 0, 1, n + 1, 1, 1, n + 1);
    add(1, 1, 1, n + 1, n, 1, n + 1);
    //cout << inv2[3] << ' ' << inv2[10] <<'\n'; 
    for (int i = m; i >= 1; i--){
        int v = E[i].v, u = E[i].u;
        int r = get(1, 1, inv2[v], inv2[v] + 1, 1, n + 1);
        int l = get(1, 0, inv2[v], inv2[v] + 1, 1, n + 1);
        //cout << v << ' ' << u << ' ' << l << ' ' << r << '\n';
		if (E[i].w > ps[r] - ps[l - 1]){
            ans++;
            if (mark[i]){
        //        cout << "YES " << i << ' ' << inv[i] << endl;
                add(1, 1, l, inv[i] + 1, inv[i], 1, n + 1);
                add(1, 0, inv[i] + 1, r + 1, inv[i] + 1, 1, n + 1);
            }
        }
    }
    cout << ans;






	return 0;
}


Measured memory_bytes: 29460