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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



int n, m;
ll x[maxn];
ll cc[maxn];
int par[maxn], siz[maxn];
int edge_deletes[maxn];

int parent(int v) {
    if (par[v]==v) return v;
    return par[v] = parent(par[v]);
}


void join(int u, int v, ll wei) {
    u = parent(u);
    v = parent(v);

    if (u == v) {
	if (wei > cc[u]) {
	    edge_deletes[u]++;
	} else {
	    edge_deletes[u]=0;
	}
    } else {
	if (siz[u]<siz[v]) swap(u,v);
	cc[u] += cc[v];
	siz[u] += siz[v];
	edge_deletes[u] += edge_deletes[v];
	par[v] = u;

	if (wei > cc[u]) {
	    edge_deletes[u]++;
	} else {
	    edge_deletes[u]=0;
	}
    }
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);

    cin>>n>>m;
    for (int i=1; i<=n; i++) {
	cin>>x[i];
    }
    for (int i=1; i<=n; i++) {
	cc[i]=x[i];
	par[i]=i;
	siz[i]=1;
    }

    vector<pair<ll,pair<int,int>>> edges;
    for (int i=0; i<m; i++) {
	int a,b,w;
	cin>>a>>b>>w;
	edges.push_back({w,{a,b}});
    }

    sort(edges.begin(), edges.end());


    for (auto ed: edges) {
	ll wei = ed.first;
	int u = ed.second.first;
	int v = ed.second.second;
	join(u,v, wei);
    }

    cout<<edge_deletes[parent(1)]<<endl;
    
    
    return 0;
}
