#include<iostream>
#include<vector>
#include<algorithm>
#define DIM 100005
#define f first
#define s second
using namespace std;
int n, m, i, r1, r2, nr;
int ff[DIM], r[DIM], viz[DIM], val[DIM];
long long sum[DIM];
vector< pair<int, int> > v[DIM];
struct str{
    int x, y, c;
};
str w[DIM];
int cmp(str a, str b){
    return a.c < b.c;
}
int rad(int x){
    while(r[x] > 0){
        x = r[x];
    }
    return x;
}
void dfs(int nod, int maxim){
    for(int i = 0; i < v[nod].size(); i++){
        int ind = v[nod][i].s;
        if(viz[ind] == 0 && w[ind].c <= maxim){
            viz[ind] = 1;
            nr++;
            dfs(v[nod][i].f, maxim);
        }
    }
}
int main(){
    cin>> n >> m;
    for(i = 1; i <= n; i++){
        cin>> val[i];
    }
    for(i = 1; i <= m; i++){
        cin>> w[i].x >> w[i].y >> w[i].c;
    }
    sort(w + 1, w + m + 1, cmp);
    for(i = 1; i <= n; i++){
        r[i] = -1;
        sum[i] = val[i];
    }
    for(i = 1; i <= m; i++){
        r1 = rad(w[i].x);
        r2 = rad(w[i].y);
        if(r1 != r2){
            if(r[r1] < r[r2]){
                r[r1] += r[r2];
                r[r2] = r1;
                sum[r1] += sum[r2];
            }
            else{
                r[r2] += r[r1];
                r[r1] = r2;
                sum[r2] += sum[r1];
            }
        }
        r1 = rad(w[i].x);
        if(sum[r1] >= w[i].c){
            ff[i] = 1;
        }
    }
    for(i = 1; i <= m; i++){
        v[ w[i].x ].push_back( make_pair(w[i].y, i) );
        v[ w[i].y ].push_back( make_pair(w[i].x, i) );
    }
    for(i = m; i >= 1; i--){
        if(viz[i] == 0 && ff[i] == 1){
            dfs(w[i].x, w[i].c);
        }
    }
    cout<< m - nr;
    return 0;
}
