#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

struct edge {
    int u,v,w;
    bool operator<(const edge& a) const {
        return w < a.w;
    }
};

struct UnionFind {
private:
    vector<int> par,sizes;
public:
    UnionFind (int n) {
        par.resize(n);
        sizes = vector<int>(n,1);
        for (int i = 0;i < n;++i) par[i] = i;
    }

    int find(int x) {
        if (par[x] == x) return x;
        else return par[x] = find(par[x]);
    }

    void unite(int x,int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (sizes[x] < sizes[y]) swap(x,y);
        par[y] = x;
        sizes[x] += sizes[y];
    }

    bool same(int x,int y) {
        return find(x) == find(y);
    }

    int size(int x) {
        return sizes[find(x)];
    }
};

int main() {
    int n,m;
    cin >> n >> m;
    vector<int> x(n),t(n,0);
    vector<ll> w(n,0);
    vector<edge> a(m);
    UnionFind uf(n);
    for (int i = 0;i < n;++i) cin >> x[i];
    for (int i = 0;i < n;++i) w[i] = x[i];
    for (int i = 0;i < m;++i) {
        cin >> a[i].u >> a[i].v >> a[i].w;
        a[i].u--;
        a[i].v--;
    }
    sort(a.begin(),a.end());
    for (int i = 0;i < m;++i) {
        int u = uf.find(a[i].u),v = uf.find(a[i].v);
        if (uf.same(u,v)) {
            if (w[u] >= a[i].w) t[u] = 0;
            else t[u]++;
        } else {
            if (uf.size(u) < uf.size(v)) swap(u,v);
            if (w[u]+w[v] >= a[i].w) t[u] = 0;
            else t[u] += t[v]+1;
            w[u] += w[v];
            uf.unite(u,v);
        }
    }
    cout << t[uf.find(0)] << endl;
    return 0;
}