#include <bits/stdc++.h>

using namespace std;

#define REP(var, n)  for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

#define all(c) begin(c),end(c)

#define D(x) do { std::cerr << x; } while (0)
#define D2(x) do { std::cerr << #x << ": " << x << std::endl; } while (0)


template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}

class UnionFind {
    vi par;
    vi rank;
public:
    vll sum;

    UnionFind(int n, vi w) {
        par.resize(n);
        rank.resize(n);
        sum.resize(n);
        REP(i, n) {
            par[i] = i;
            rank[i] = 0;
            sum[i] = w[i];
        }
    }

    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;

        ll tx = sum[par[x]];
        ll ty = sum[par[y]];

        if (rank[x] < rank[y])
            par[x] = y;
        else {
            par[y] = x;
            if (rank[x] == rank[y])
                rank[x]++;
        }

        sum[find(par[x])] = tx + ty;
    }

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


auto solve() {
    int N, M;
    cin >> N >> M;

    vi X(N);
    for (auto &&e: X) cin >> e;

    vector<pair<int, pii>> edges(M);
    REP(i, M) {
        int a, b, y;
        cin >> a >> b >> y;
        --a, --b;
        edges[i] = make_pair(y, make_pair(a, b));
    }
    sort(all(edges));

    UnionFind uf = UnionFind(N, X);
    int c = 0;
    int mc = 0;
    for (auto &&e:edges) {
        c++;

        int v = e.first;
        int p1 = e.second.first;
        int p2 = e.second.second;

        uf.unite(p1, p2);
        if (uf.sum[uf.find(p1)] >= v)
            mc = c;
    }

    return M - mc;
}


int main() {
    cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);

//    cout << (solve() ? "Yes" : "No") << endl;
//    cout << (solve() ? "YES" : "NO") << endl;
    cout << solve() << endl;
//    solve();

    return 0;
}
