/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

struct UnionFind {
    vector<int> par, w, sum;
    
    UnionFind(int n, vector<int> x) : par(n, -1), w(n, 0) { sum = x; }
    void init(int n) { par.assign(n, -1); w.assign(n, 0); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) {
            ++w[x];
            return false;
        }
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        sum[x] += sum[y];
        par[y] = x;
        w[x] += w[y];
        ++w[x];
        return true;
    }

    int xsum(int x) {
        return sum[root(x)];
    }
    
    int size(int x) {
        return -par[root(x)];
    }
 
    int wei(int x) {
        return w[root(x)];
    }
};

int n, m;
vector<int> x;
vector<vector<P>> g;

typedef pair<int, pair<int, int>> P2;

map<pair<int, int>, int> mp;

vector<bool> ok;

void dfs(int v, int val) {
    for(P e: g[v]) {
        if(e.sc <= val && !ok[mp[{v, e.fr}]]) {
            ok[mp[{v, e.fr}]] = 1;
            dfs(e.fr, val);
        }
    }
}

void solve() {
	cin >> n >> m;
    x.resize(n);
    rep(i, n) {
        cin >> x[i];
    }
    g.assign(n, vector<P>());
    vector<P2> es(m);
    rep(i, m) {
        int a, b, y; cin >> a >> b >> y;
        -- a, -- b;
        g[a].pb({b, y});
        g[b].pb({a, y});
        es[i] = {y, {a, b}};
    }
    UnionFind uf(n, x);
    sort(all(es));
    rep(i, m) {
        mp[{es[i].sc.fr, es[i].sc.sc}] = i;
        mp[{es[i].sc.sc, es[i].sc.fr}] = i;
    }
    vector<bool> cand(m, 0);
    rep(i, m) {
        int val = es[i].fr, a = es[i].sc.fr, b = es[i].sc.sc;
        uf.merge(a, b);
        if(uf.xsum(a) >= val) {
            cand[i] = 1;
        }
    }
    ok.assign(m, 0);
    per(i, m) {
        if(cand[i]) {
            if(!ok[i]) {
                dfs(es[i].sc.sc, es[i].fr);
            }
        }
    }
    int cnt = 0;
    rep(i, m) {
        if(!ok[i]) ++ cnt;
    }
    cout << cnt << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 36592