#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define ROF(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define REP(i, n) FOR(i, 0, (n)-1)
#define sqr(x) ((x) * (x))
#define all(x) (x).begin(), (x).end()
#define reset(x, y) memset(x, y, sizeof(x))
#define uni(x) (x).erase(unique(all(x)), (x).end());
#define BUG(x) cerr << #x << " = " << (x) << endl
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define _1 first
#define _2 second

const int maxn = 112345;

ll x[maxn], has[maxn], need[maxn];
int p[maxn], cnt[maxn], ans, n, m;
vector<pair<ll, pii>> e;

int Find(int x) {
    return p[x] == x ? x : p[x] = Find(p[x]);
}

void Union(int u, int v, ll to) {
    int fu = Find(u), fv = Find(v);
    if (fu == fv) {
        cnt[fu]++;
        need[fu] = to;
        return;
    }
    p[fu] = fv;
    cnt[fv] += cnt[fu] + 1;
    has[fv] += has[fu];
    need[fv] = to;
}

int main() {
    scanf("%d%d", &n, &m);
    FOR(i, 1, n) scanf("%lld", x + i);
    FOR(i, 1, n) {
        p[i] = i;
        has[i] = x[i];
    }
    FOR(i, 1, m) {
        ll y;
        int u, v;
        scanf("%d%d%lld", &u, &v, &y);
        e.eb(y, mp(u, v));
    }
    sort(all(e));
    for (const auto &cur : e) {
        ll now = cur._1;
        int u = cur._2._1, v = cur._2._2;
        Union(u, v, now);
        int r = Find(u);
        if (has[r] >= need[r]) {
            ans += cnt[r];
            cnt[r] = 0;
        }
    }
    printf("%d", m - ans);
}