#include <bits/stdc++.h>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

struct TTNode {
    using NP = TTNode*;

    bool rev = false;
    array<array<NP, 2>, 2> ch = {}; //tree, light-tree
    NP p = nullptr, lt = nullptr;

    struct D {
        ll sm;
        // l is parent of r
        static D merge_h(const D& l, const D& r) {
            return {l.sm + r.sm};
        }
        // l and r is parallel
        static D merge_w(const D& l, const D& r) {
            return {l.sm + r.sm};
        }
        // add parent for r(subtrees)
        static D join(const D& l, const D& r) {
            return {l.sm + r.sm};
        }
        D rev() { return *this; }
        D to_subs() { return *this; }
    };
    D single = D(), sub = D(), subs = D();

    void init_node(ll _sm) {
        single.sm = _sm;
        update();
    }
    void update_subs() {
        subs = sub.to_subs();
        if (ch[1][0]) subs = D::merge_w(ch[1][0]->subs, subs);
        if (ch[1][1]) subs = D::merge_w(subs, ch[1][1]->subs);
    }
    void update() {
        assert(!rev);
        sub = single;
        if (lt) sub = D::join(single, lt->subs);
        if (ch[0][0]) sub = D::merge_h(ch[0][0]->sub, sub);
        if (ch[0][1]) sub = D::merge_h(sub, ch[0][1]->sub);
        update_subs();
    }
    void revdata() {
        rev ^= true; swap(ch[0][0], ch[0][1]); // Important
        sub = sub.rev();
        update_subs();
    }
    void push() {
        if (rev) {
            if (ch[0][0]) ch[0][0]->revdata();
            if (ch[0][1]) ch[0][1]->revdata();
            rev = false;
        }
    }
    //optimize? : template<int ty>
    int pos(int ty) {
        if (p) {
            if (p->ch[ty][0] == this) return 0;
            if (p->ch[ty][1] == this) return 1;
        }
        return -1;
    }
    static void con(NP p, NP& cp, NP ch) { cp = ch; if (ch) ch->p = p; }
    void rot(int ty) {
        int ps = pos(ty);
        NP _p = p, q = p->p;
        if (ty == 0) {
            ch[1] = _p->ch[1]; _p->ch[1].fill(nullptr);
            for (auto& x: ch[1]) if (x) x->p = this;
        }
        con(_p, _p->ch[ty][ps], ch[ty][1-ps]);
        con(this, ch[ty][1-ps], _p);
        _p->update(); update();
        p = q;
        if (!q) return;
        if (q->lt == _p) q->lt = this;
        for (auto& v: q->ch) for (auto& x: v) if (x == _p) x = this;
        q->update();
    }
    void splay(int ty) {
        int ps;
        while ((ps = pos(ty)) != -1) {
            int pps = p->pos(ty);
            if (pps == -1) {
                rot(ty);
            } else if (ps == pps) {
                p->rot(ty); rot(ty);
            } else {
                rot(ty); rot(ty);
            }
        }
    }
    void expose() {
        supush();
        splay(0); splay(1);
        if (NP z = ch[0][1]) {
            z->push();
            con(z, z->ch[1][1], lt);
            lt = z; ch[0][1] = nullptr;
            z->update(); update();
        }
        NP u = p;
        while (u) {
            u->splay(0); u->splay(1);
            NP ur = u->lt;
            if (auto r = u->ch[0][1]) {
                // swap ur, r
                r->push();
                r->ch[1] = ur->ch[1]; ur->ch[1].fill(nullptr);
                for (auto& x: r->ch[1]) if (x) x->p = r;
                r->update();
                u->lt = r;
            } else if (!ur->ch[1][0]) {
                // use ur->ch[1][1]
                con(u, u->lt, ur->ch[1][1]);
            } else {
                // use prev(ur) in light-tree
                NP q = ur->ch[1][0];
                con(u, u->lt, q);
                q->push();
                while (q->ch[1][1]) {
                    q = q->ch[1][1]; q->push();
                }
                q->splay(1);
                con(q, q->ch[1][1], ur->ch[1][1]); q->update();
            }
            ur->ch[1].fill(nullptr); ur->update();
            u->ch[0][1] = ur; u->update();
            u = u->p;
        }
        splay(0);
    }
    void supush() {
        if (p) p->supush();
        push();
    }
    void link(NP r) {
        evert(); r->expose();
        assert(!r->ch[0][1]);
        con(r, r->ch[0][1], this);
        r->update();
    }
    void cut() {
        expose();
        assert(ch[0][0]);
        ch[0][0]->p = nullptr; ch[0][0] = nullptr;
        update();
    }
    void evert() {
        expose();
        revdata();
        expose();
    }
};

TTNode tn[100100];

struct UnionFind {
    V<int> p, r;
    int gn;
    UnionFind(int n = 0) : p(n, -1), r(n, 1), gn(n) {}
    void merge(int a, int b) {
        int x = group(a), y = group(b);
        if (x == y) return;  // same
        gn--;
        if (r[x] < r[y])
            p[x] = y;
        else if (r[x] > r[y])
            p[y] = x;
        else {
            p[x] = y;
            r[x]++;
        }
    }
    int group(int a) {
        if (p[a] == -1) return a;
        return p[a] = group(p[a]);
    }
    bool same(int a, int b) { return group(a) == group(b); }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << fixed;

    int n, m;
    cin >> n >> m;
    V<ll> x(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
        tn[i].init_node(x[i]);
    }
    struct E {
        int from, to;
        ll cost;
    };
    V<E> edges;
    for (int i = 0; i < m; i++) {
        int a, b; ll y;
        cin >> a >> b >> y; a--; b--;
        edges.push_back(E{a, b, y});
    }
    sort(edges.begin(), edges.end(), [&](E a, E b){
        return a.cost < b.cost;
    });
    auto uf = UnionFind(n);
    V<E> tr_edges;
    for (auto e: edges) {
        if (uf.same(e.from, e.to)) continue;
        tr_edges.push_back(e);
        uf.merge(e.from, e.to);
        tn[e.from].link(tn + e.to);
    }
    reverse(tr_edges.begin(), tr_edges.end());

    V<E> n_tr_edges;
    for (auto e: tr_edges) {
        tn[e.from].evert();
        tn[e.to].expose();
        ll z = tn[e.to].subs.sm;
        if (z < e.cost) {
            tn[e.to].cut();
        } else {
            n_tr_edges.push_back(e);
        }
    }
    auto uf2 = UnionFind(n);
    for (auto e: n_tr_edges) uf2.merge(e.from, e.to);

    int ans = 0;
    for (auto e: edges) {
        if (!uf2.same(e.from, e.to)) {
            ans++;
            continue;
        }
        tn[e.from].evert();
        tn[e.to].expose();
        ll z = tn[e.to].subs.sm;
        if (z < e.cost) ans++;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 15856