#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e16+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct UnionFind {
    vector<int> par;
    vector<pair<P,int>> size;
    UnionFind(int x,vector<int> y) {
        par.resize(x);
        size.resize(x);
        for(int i = 0; i < x; i++) {
            par[i] = i;
        }
        for(int i = 0; i < x; i++) {
            size[i].first.second = y[i];
            size[i].second = 1;
        }
    }
    int find(int x) {
        if (par[x] == x)
            return x;
        return par[x] = find(par[x]);
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    P consize(int x) {
        return {size[find(x)].first.first,size[find(x)].first.second};
    }
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y)
            return;
        if (size[x].second < size[y].second) {
            par[x] = y;
            size[y].first.first += size[x].first.first;
            size[y].first.second += size[x].first.second;
            size[y].second += size[x].second;
        }
        else {
            par[y] = x;
            size[x].first.first += size[y].first.first;
            size[x].first.second += size[y].first.second;
            size[x].second += size[y].second;
        }
    }
};
int now = 0;
vector<P> g[100005];
void dfs(vector<bool> &hantei,int n) {
    for(P x:g[n]) {
        if(!hantei[x.first]) {
            if(now >= x.second) {
                hantei[x.first] = true;
                dfs(hantei,x.first);
            }
        }
    }
}
signed main(){
    int N,M;
    cin >> N >> M;
    vector<int>X(N);
    for(int i = 0; i < N; i++) {
        cin >> X[i];
    }
    vector<pair<int,P>>hen(M);
    for(int i = 0; i < M; i++) {
        cin >> hen[i].second.first >> hen[i].second.second >> hen[i].first;
        hen[i].second.first--;
        hen[i].second.second--;
        g[hen[i].second.first].push_back({hen[i].second.second,hen[i].first});
        g[hen[i].second.second].push_back({hen[i].second.first,hen[i].first});
    }
    sort(hen.begin(),hen.end());
    UnionFind uf(N,X);
    vector<bool>ok(M);
    for(int i = 0; i < M; i++) {
        uf.unite(hen[i].second.first,hen[i].second.second);
        uf.size[uf.find(hen[i].second.first)].first.first++;
        if(uf.consize(hen[i].second.first).second >= hen[i].first) {
            ok[i] = true;
        }
    }
    vector<P>flag(M);
    for(int i = 0; i < M; i++) {
        flag[i].first = hen[i].first;
        flag[i].second = i;
    }
    sort(flag.rbegin(),flag.rend());
    vector<bool>hantei(N);
    int cnt = 0;
    for(int i = 0; i < M; i++) {
        if(ok[flag[i].second]) {
            cnt++;
            now = flag[i].first;
            hantei[hen[flag[i].second].second.first] = true;
            hantei[hen[flag[i].second].second.second] = true;
            dfs(hantei,hen[flag[i].second].second.first);
            dfs(hantei,hen[flag[i].second].second.second);
        }
        else {
            if(hantei[hen[flag[i].second].second.first] && hantei[hen[flag[i].second].second.second]) {
                cnt++;
            }
        }
    }
    cout << M-cnt << endl;
}


Measured memory_bytes: 23064