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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

template <typename T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

class union_find {
private:
    vector<int> parent, rank, gs;
    int size;

public:
    int count_group;
    union_find() = default;
    union_find(int n) { init(n); }

    void init(int n) {
        size = n;
        count_group = n;
        parent.resize(size);
        rank.assign(size, 0);
        gs.assign(size, 1);
        for (int i = 0; i < size; ++i) parent[i] = i;
    }

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

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (rank[x] < rank[y]) {
            parent[x] = y;
            gs[y] += gs[x];
        } else {
            parent[y] = x;
            gs[x] += gs[y];
            if (rank[x] == rank[y]) ++rank[x];
        }
        --count_group;
    }

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

    int group_size(int x) {
        return gs[find(x)];
    };
};

void solve() {
    //const i64 mod = 1'000'000'007;
    i64 N,M;
    cin >> N >> M;

    vector<i64> X(N);
    rep(i,0,N) cin >> X[i];

    vector<i64> A(M),B(M),Y(M);
    rep(i,0,M){
        cin >> A[i] >> B[i] >> Y[i];
        --A[i];
        --B[i];
    }

    vector<tuple<i64,i64,i64>> edges;
    rep(i,0,M) edges.emplace_back(make_tuple(Y[i],A[i],B[i]));
    sort(begin(edges),end(edges));

    union_find uf(N);
    vector<i64> sum(N),maxe(N),nece_sum(M);
    rep(i,0,N) sum[i]=X[i];
    rep(i,0,M){
        i64 c,u,v;
        tie(c,u,v)=edges[i];
        u=uf.find(u);
        v=uf.find(v);
        if(u==v){
            chmax(maxe[u],c);
            nece_sum[i]=sum[u];
        }else{
            uf.unite(u,v);
            if(v==uf.find(u)) swap(u,v);
            chmax(maxe[u],maxe[v]);
            chmax(maxe[u],c);
            sum[u]+=sum[v];
            nece_sum[i]=sum[u];
        }
    }

    vector<bool> fixed(N);
    vector<set<i64>> graph(N);

    rep(i,0,M){
        i64 c,u,v;
        tie(c,u,v)=edges[i];
        graph[u].insert(v);
        graph[v].insert(u);
    }

    function<void(i64)> dfs=[&](i64 u){
        fixed[u]=true;
        for(auto v:graph[u]){
            if(fixed[v]) continue;
            dfs(v);
        }
    };

    i64 ans=0;
    for(i64 i=M-1; i>=0; --i){
        i64 c,u,v;
        tie(c,u,v)=edges[i];
        if(fixed[u]) continue;
        if(nece_sum[i]<c){
            ++ans;
            graph[u].erase(v);
            graph[v].erase(u);
            continue;
        }
        dfs(u);
    }

    cout << ans << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 28016