#include<bits/stdc++.h>
#define int long long
typedef long long ll;
using namespace std;

struct edge{
    ll u, v, w;
};

struct xzkaknazvat{
    ll cost, black;
};

bool operator < (edge a, edge b){
    return a.w < b.w;
}

ll n,m;
vector<ll> a;
vector<edge> g;
vector<ll> p;
vector<ll> sz;
vector<xzkaknazvat> d;

ll get_sqrt(ll v){
    if(p[v] == v){
        return v;
    }
    ll x = get_sqrt(p[v]);
    p[v] = x;
    return x;
}


bool check(int u, int v){
    return get_sqrt(u) == get_sqrt(v);
}

void unio(int u, int v, int typreb){
    if(sz[v] > sz[u]){
        swap(sz[v],sz[u]);
    }
    if(sz[v] == sz[u]){
        sz[u]++;
    }
    d[u].cost += d[v].cost;
    d[u].black += d[v].black;
    d[u].black*=typreb;
    d[u].black+=typreb;
    p[v] = u;
}


main(){
    cin >> n >> m;

    p.resize(n+1);
    for(int i=0;i<=n;++i){
        p[i] = i;
    }
    sz.assign(n+1, 1);
    a.resize(n+1);
    for(int i=1;i<=n;++i){
        cin >> a[i];
    }

    d.resize(n+1);
    for(int i=1;i<=n;++i){
        d[i] = {a[i], 0};
    }

    g.resize(m+1);
    ll f1,f2,f3;
    for(int i=0;i<m;++i){
        cin >> f1 >> f2 >> f3;
        g[i] = {f1,f2,f3};
    }
    sort(g.begin(),g.end());


    for(int i=0;i<m;++i){
        int u = get_sqrt(g[i].u);
        int v = get_sqrt(g[i].v);
        if(u == v){
            if(d[u].cost >= g[i].w){
                d[u].black = 0;
            }
            continue;
        }
        if(sz[u] + sz[v] >= g[i].w){
            unio(u,v,0);
        }
        else{
            unio(u,v,1);
        }
    }

    cout << d[get_sqrt(1)].black;

}
