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

vector<long long> X;

class union_find {
public:
    union_find(int n): par(vector<int>(n, -1)), ec(vector<int>(n, 0)), components(n) {
        W.resize(n);
        for(int i=0; i<n; ++i) W[i] = X[i];
    }

    bool unite(int x, int y) {
        if((x = find(x)) == (y = find(y))) {
            return false;
        } else {
            if(par[x] < par[y]) swap(x, y);
            par[y] += par[x];
            par[x] = y;
            W[y] += W[x];
            ec[y] += ec[x];
            --components;
            return true;
        }
    }

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

    int size(int x) {
        return -par[find(x)];
    }

    long long weight(int x) {
        return W[find(x)];
    }

    void addedge(int x) {
        ec[find(x)] += 1;
    }

    int edgenum(int x) {
        x = find(x);
        int ret = ec[x];
        ec[x] = 0;
        return ret;
    }

    int cnt() {
        return components;
    }

private:
    vector<int> par, ec;
    vector<long long> W;
    int components;
};

int main() {
    int N, M; cin >> N >> M;
    X.resize(N);
    for(int i=0; i<N; ++i) cin >> X[i];
    vector<int> A(M), B(M);
    vector<long long> Y(M);
    for(int j=0; j<M; ++j) {
        cin >> A[j] >> B[j] >> Y[j];
        --A[j]; --B[j];
    }

    vector<int> order;
    for(int j=0; j<M; ++j) order.push_back(j);
    sort(begin(order), end(order), [&](int a, int b){return Y[a] < Y[b];});

    int ans = 0;
    union_find uf(N);
    for(int i : order) {
        uf.unite(A[i], B[i]);
        uf.addedge(A[i]);
        if(Y[i] <= uf.weight(A[i])) ans += uf.edgenum(A[i]);
    }
    cout << M - ans << endl;
}