#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair
#define int         int64_t

using namespace std;

typedef pair<int, int> pii;
const int N = int(2e5 + 7);
const int inf = int(1e18);

struct TEdge {
    int u, v, w;
    TEdge() {}
    TEdge(int u, int v, int w): u(u), v(v), w(w) {}
    bool operator < (const TEdge& o) const& {
        return w < o.w;
    }
};
int n, m, res, cnte[N], lab[N], w[N];
vector<TEdge> e;

int Find(int x) {return lab[x] < 0? x: lab[x] = Find(lab[x]);}
void Union(int r, int s, int W) {
    if(r != s) {
        if(lab[r] > lab[s]) swap(r, s);
        cnte[r] += cnte[s], w[r] += w[s], lab[r] += lab[s], lab[s] = r;
    }
    if(w[r] >= W) {
        res += cnte[r] + 1;
        cnte[r] = 0;
    } else ++cnte[r];
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> n >> m; memset(&lab, -1, sizeof lab);
    for(int i = 1; i <= n; ++i) cin >> w[i];
    e.resize(m); for(TEdge& ed: e) cin >> ed.u >> ed.v >> ed.w;
    sort(e.begin(), e.end());
    for(TEdge& ed: e) Union(Find(ed.u), Find(ed.v), ed.w);
    cout << m - res;
}
