#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 final
{
public:
    using data_type = int64_t;
    using size_type = uint64_t;

    data_type none = -1;

    // data_[index]の値が親要素を表す(noneはroot)
    std::vector<data_type> data_;
    // rootの集合
    std::set<data_type> roots_;
    // そのグループの要素の数
    std::vector<size_type> size_;

    // indexのrootを求める
    data_type root(data_type index)
    {
        // グループ番号がnoneならそれがroot
        if(data_[index] == none)
            return index;
        // 親へのindexをrootに付け替える(高速化)
        data_[index] = root(data_[index]);
        return data_[index];
    }

    union_find(data_type size)
        : data_(size, none), size_(size, 1)
    {
    }

    // aとbを同じグループにする
    void unite(data_type a, data_type b)
    {
        a = root(a);
        b = root(b);
        
        // aとbのrootが同じならすでに同じグループ
        if(a == b) return;
        
        // 要素の多い方に付け替える(高速化)
        if(size_[a] < size_[b]) {
            data_[b] = a;
            size_[a] = size_[a] + size_[b];
            roots_.erase(b);
            roots_.insert(a);
        } else {
            data_[a] = b;
            size_[b] = size_[a] + size_[b];
            roots_.erase(a);
            roots_.insert(b);
        }
    }

    bool is_union(data_type a, data_type b)
    {
        return root(a) == root(b);
    }
    
    // ↓あると便利なの

    const std::set<data_type>& roots() const
    {
        return roots_;
    }

    size_type maximum() const
    {
        return *std::max_element(size_.begin(), size_.end());
    }
    size_type minimum() const
    {
        return *std::min_element(size_.begin(), size_.end());
    }
};

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.root(a)];
        }else{
            sXtmp[i] = sX[U.root(a)] + sX[U.root(b)];
            U.unite(a, b);
            sX[U.root(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