#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &&x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define INSEG(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void PSUM(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(false);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

struct union_find {
    vector<int> data;
    vector<int> w;
    union_find(int size) : data(size, -1), w(size) {}
    void set(int i, int x) {
        w[i] = x;
    }
    void unite(int x, int y) {
        x = root(x); y = root(y);
        if(x != y) {
            if(data[y] < data[x]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
            w[x] += w[y];
        }
    }
    int weight(int x) {
        x = root(x);
        return w[x];
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : (data[x] = root(data[x]));
    }
    int size(int x) {
        return -data[root(x)];
    }
};

signed main() {
    int N, M;
    cin >> N >> M;
    vector<int> X(N);
    cin >> X;
    union_find uf(N);
    REP(i, N) uf.set(i, X[i]);

    vector<vi> E(M);
    vector<vector<pii>> g(N);
    REP(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        E[i] = {c, a, b};
    }
    sort(ALL(E));
    REP(i, M) {
        int a = E[i][1];
        int b = E[i][2];
        g[a].push_back({b, i});
        g[b].push_back({a, i});
    }
    
    vector<int> wlog(M);
    REP(i, M) {
        int a = E[i][1];
        int b = E[i][2];
        if (!uf.same(a, b)) {
            uf.unite(a, b);
        }
        wlog[i] = uf.weight(a);
    }

    int ans = 0;
    vector<bool> alive(M, true);
    REPR(i, M - 1) {
        int c = E[i][0];
        int a = E[i][1];
        int b = E[i][2];
        if (!alive[i]) continue;

        auto w = wlog[i];
        if (w >= c) {
            queue<int> q;
            q.push(a);
            while (!q.empty()) {
                int v = q.front(); q.pop();
                FORE(e, g[v]) {
                    int w = e.first;
                    int idx = e.second;
                    if (!alive[idx]) continue;
                    alive[idx] = false;
                    q.push(w);
                }
            }
        } else {
            alive[i] = false;
            ans++;
        }
    }
    cout << ans << endl;
    return (0^_^0);
}



Measured memory_bytes: 16640