#include <bits/stdc++.h>

using namespace std;


vector <long long> d;
vector <long long> w;
vector <long long> tp;
vector <pair <long long, long long>> a;
vector <pair <long long, long long>> y;

struct SNM {
    long long n;
    vector <long long> root;
    vector <long long> cmp;
    vector <long long> h;
    vector <long long> bl;
    vector <long long> sm;
    void reset(long long x, long long m) {
        n = x;
        //
        root.clear();
        root.resize(n + 5);
        for (long long i = 1; i <= n; ++i) {
            root[i] = i;
        }
        //
        cmp.clear();
        cmp.resize(n + 5);
        for (long long i = 1; i <= n; ++i) {
            cmp[i] = i;
        }
        //
        h.clear();
        h.resize(n + 5, 0);
        sm.resize(n + 5, 0);
        bl.resize(n + 5, 0);
        for (long long i = 1; i <= n; ++i) {
            sm[i] = w[i];
        }


    }

    long long get(long long v) {
        if (cmp[v] == v) {
            return v;
        }
        long long x = get(cmp[v]);
        cmp[v] = x;
        return x;
    }

    bool join(long long j) {
        long long u = y[j].first, v = y[j].second;
        u = get(u), v = get(v);

        if (u == v) {
            if (d[j] <= sm[u]) {
                bl[u] = 0;
            } else {
                ++bl[u];
            }
        } else {

            if (h[v] == h[u]) {
                cmp[u] = v;
                ++h[v];

                bl[v] += bl[u];
                sm[v] += sm[u];

                if (d[j] <= sm[v]) {
                    bl[v] = 0;
                } else {
                    ++bl[v];
                }
            } else {
                if (h[v] < h[u]) {
                    cmp[u] = v;

                    bl[v] += bl[u];
                    sm[v] += sm[u];

                    if (d[j] <= sm[v]) {
                        bl[v] = 0;
                    } else {
                        ++bl[v];
                    }
                } else {

                    cmp[v] = u;

                    bl[u] += bl[v];
                    sm[u] += sm[v];

                    if (d[j] <= sm[u]) {
                        bl[u] = 0;
                    } else {
                        ++bl[u];
                    }
                }

            }
        }
        return true;
    }

    bool check(long long v, long long u) {
        return get(v) == get(u);
    }

};

int main() {

    long long n, m;
    cin >> n >> m;

    d.resize(m + 5);
    w.resize(n + 5);
    y.resize(m + 5);

    for (long long i = 1; i <= n; ++i) {
        cin >> w[i];
    }

    // 0 - black, 1 - white

    for (long long j = 1; j <= m; ++j) {
        long long v, to, wi;
        cin >> v >> to >> wi;
        d[j] = wi;
        a.emplace_back(wi, j);
        y[j].first = v;
        y[j].second = to;
    }

    sort(a.begin(), a.end());


    SNM sn;
    sn.reset(n, m);

    long long ans = 0;
    for (auto i : a) {
        sn.join(i.second);
    }

    bool ma[n + 5];

    for(auto & i : ma) {
        i = false;
    }

    for (long long i = 1; i <= n; ++i) {
        if (!ma[sn.get(i)]) {
            ans += sn.bl[sn.get(i)];
            ma[sn.get(i)] = true;
        }
    }

    cout << ans << '\n';






    return 0;
}


//18 14
//1 2 8
//1 4 9
//2 10 19
//10 11 49
//10 12 35
//2 5 17
//5 8 27
//5 9 20
//2 3 3
//3 7 6
//3 6 7
//13 14 1
//15 16 2
//17 18 3

Measured memory_bytes: 9456