
#include <bits/stdc++.h>

#define null               ""
#define all(dat)           dat.begin(), dat.end()
#define over(msg)          cout << msg << endl, exit(0);
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fr, to)    for (int i = fr; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

struct edge {
    int u, v, val;
    edge() {}
    edge(int u, int v, int val) {
        this->u = u;
        this->v = v;
        this->val = val;
    }
};

int n, m, s, pr[100005], sz[100005];
num w[100005];
edge dat[100005];

bool cmp(edge a, edge b) {
    return a.val < b.val;
}

int find_pr(int a) {
    return pr[a] == a ? a : pr[a] = find_pr(pr[a]);
}

void unite(int u, int v) {
    int pu = find_pr(u), pv = find_pr(v);
    if (pu == pv)  return;
    pr[pv] = pu;
    w[pu] += w[pv];
    sz[pu] += sz[pv];
    sz[pv] = 0;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    cont (i, n) {
        cin >> w[i];
        pr[i] = i;
    }
    cont (i, m) {
        int u, v, val;
        cin >> u >> v >> val;
        dat[i] = edge(u, v, val);
    }
    sort(dat + 1, dat + m + 1, cmp);
    cont (i, m) {
        int u = dat[i].u, v = dat[i].v, val = dat[i].val;
        unite(u, v);
        int p = find_pr(u);
        ++sz[p];
        if (w[p] >= val) {
            s += sz[p];
            sz[p] = 0;
        }
    }
    cout << m - s << endl;
}
