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

#define mp make_pair
#define pb push_back
#define fst first
#define snd second
#define int long long
#define fast_io() ios::sync_with_stdio(false)
#define FOR(i, l, r) for(int i = (l); i < (r); i++)
#define H(x) cout << #x << " " << x << endl;

typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef set<int> si;
typedef double ld;
typedef pair<ld, ld> dd;

const ll INF = 1000000000000000000LL;
const int NMAX = 1e6+4;
const int mod = 1e9+7;
const ld eps = 1e-10;
const ld PI = acos(-1);

vi par;
vi maxedge, vertsum, maxsize, sz;
int find (int u) {
    return par[u] = par[u] == u ? u : find(par[u]);
}

void comb(int u, int v, int w) {
    u = find(u); v = find(v);
    if(u != v) {
        par[v] = u;
        maxedge[u] = max(maxedge[u], maxedge[v]);
        vertsum[u] += vertsum[v];
        sz[u] += sz[v];
        maxsize[u] += maxsize[v];
    }
    sz[u] ++;
    maxedge[u] = max(maxedge[u], w);
    if(maxedge[u] <= vertsum[u]) maxsize[u] = sz[u];
}

struct edge {
    int u, v, l;
};

bool lt (const edge &e1, const edge &e2){
    return e1.l < e2.l;
}

vector<edge> edges;

signed main(){
    int N, M;
    cin >> N >> M;
    vertsum.resize(N);
    par.resize(N);
    maxedge.assign(N, 0);
    maxsize.assign(N, 0);
    sz.assign(N, 0);
    FOR(i, 0, N) par[i] = i;
    FOR(i, 0, N) {
        int x;
        cin >> x;
        vertsum[i] = x;
    }  
    FOR(i, 0, M){  
        int u, v, w;
        cin >> u >> v >> w;
        u--; v--;
        edges.pb({u,v,w});
    }
    sort(edges.begin(), edges.end(), lt);
    for(edge e : edges){
        comb(e.u, e.v, e.l);
    }
    int tot = 0;
    FOR(i, 0, N) if(find(i) == i) tot += maxsize[i];
    cout << M-tot << endl; 
}