#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define int long long
#define INF 1000000000000000000
using namespace std;

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
template<typename T>
void debug(vector<vector<T>> m){ REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;} }

class Union_find
{
public:
    vector<int> par;
    vector<int> sz;

    Union_find(int N){
        par = vector<int>(N);
        REP(i, N) par[i] = i;
        sz = vector<int>(N, 1);
    }

    int find(int x){
        if(par[x] == x) return x;
        else return par[x] = find(par[x]);
    }

    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;

        if(sz[x] < sz[y]) swap(x, y);

        par[y] = x;
        sz[x] += sz[y];
    }

    bool is_union(int x, int y){
        x = find(x);
        y = find(y);
        return x == y;
    }

    int union_size(int x){
        return sz[find(x)];
    }

};


struct edge{int to, cost;};

class Graph
{
public:
    int V;
    vector<vector<edge>> G;

    Graph(int V): V(V){
        G = vector<vector<edge>>(V, vector<edge>(0));
    }

    void add_edge(int from, int to, int cost){
        G[from].push_back(edge({to, cost}));
    }

    void add_edge2(int v1, int v2, int cost){
        add_edge(v1, v2, cost);
        add_edge(v2, v1, cost);
    }

    void erase_edge(int from, int to){
        vec e(0);
        REP(i, G[from].size()){
            if(G[from][i].to == to) e.push_back(i);
        }
        IREP(i, e.size()) G[from].erase(G[from].begin() + e[i]);
    }

    void erase_edge2(int v1, int v2){
        erase_edge(v1, v2);
        erase_edge(v2, v1);
    }

    void dfs(int v, map<Pii, bool> &used){
        REP(k, G[v].size()){
            int a = min(v, G[v][k].to), b = max(v, G[v][k].to);
            if(!used[Pii(a, b)]){
                used[Pii(a, b)] = true;
                dfs(G[v][k].to, used);
            }
        }
    }

};

signed main(){

    int N, M; cin >> N >> M;
    vec X(N); readv(X);

    vec A(M), B(M), Y(M);
    vector<PiP> p(M);
    Graph G(N);
    Union_find U(N);
    REP(i, M){
        cin >> A[i] >> B[i] >> Y[i];
        int a = min(A[i], B[i]) - 1, b = max(A[i], B[i]) - 1;
        p[i] = PiP(Y[i], Pii(a, b));
        G.add_edge2(a, b, 0);
    }

    Sort(p);
    vec sX(N), sXtmp(M);
    REP(i, N) sX[i] = X[i];
    REP(i, M){
        int a = p[i].second.first, b = p[i].second.second;
        if(U.is_union(a, b)){
            sXtmp[i] = sX[U.find(a)];
        }else{
            sXtmp[i] = sX[U.find(a)] + sX[U.find(b)];
            U.unite(a, b);
            sX[U.find(a)] = sXtmp[i];
        }
        //cout << sXtmp[i] << endl;
    }

    map<Pii, bool> used;
    int ans = 0;
    IREP(i, M){
        int y = p[i].first;
        int a = p[i].second.first, b = p[i].second.second;
        if(used[Pii(a, b)]) continue;
        if(sXtmp[i] >= y){
            G.dfs(a, used);
        }else{
            ans++;
            G.erase_edge2(a, b);
        }
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 28800