#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
using namespace std;

int wts[100010];
tuple<int,int,int> edges[100010];
vector<int> etree[100010];
bool valid[100010];

int p[100010],r[100010],ce[100010];
long long w[100010];


int findS(int x){
    if(p[x] != x) p[x] = findS(p[x]);
    return p[x];
}
void dfs(int u){
    if(u == -1) return;
    valid[u] = true;
    for(auto v: etree[u]) dfs(v);
    etree[u].clear();
}
void mergeS(int x,int y,int e){
    x = findS(x); y = findS(y);
    if(x == y){
        etree[e].push_back(ce[x]);
        ce[x] = e;
        return;
    }

    etree[e].push_back(ce[x]);
    etree[e].push_back(ce[y]);
    if(r[x] > r[y]){
        w[x] += w[y];
        p[y] = x;
        ce[x] = e;
    }else{
        w[y] += w[x];
        p[x] = y;
        ce[y] = e;
    }

    if(r[x] == r[y]) r[y] += 1;
}

int main(){
    int N,M; cin>>N>>M;
    for(int i=1;i<=N;i++) cin>>wts[i];
    for(int i=0;i<M;i++){
        int x,y,w;cin>>x>>y>>w;
        edges[i] = make_tuple(w,x,y);
    }

    sort(edges,edges+M);
    for(int i=1;i<=N;i++){
        p[i] = i;
        w[i] = wts[i];
        ce[i] = -1;
    }

    for(int i=0;i<M;i++){
        int cw = get<0>(edges[i]),x = get<1>(edges[i]), y = get<2>(edges[i]);
        mergeS(x,y,i);
        int pi = findS(x);
        if(w[pi] >= cw) dfs(ce[pi]);
    }

    int rm = 0;
    for(int i=0;i<M;i++) if(valid[i] == false) rm += 1;
    cout<<rm<<endl;
    return 0;
}