#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)


class UnionFind {
private:
    
public:
    ll sz;
    vector<ll> par, size_;
    UnionFind(){}
    UnionFind(int node_size) : sz(node_size), par(sz), size_(sz, 1){
        iota(par.begin(), par.end(), 0);
    }
    int find(int x){
        if(par[x] == x) return x;
        else return par[x] = find(par[x]);
    }
    void unite(int x,int y){
        x = find(x), y = find(y);
        if(x == y) return;
        if(size_[x] < size_[y]) swap(x,y);
        par[y] = x;
        size_[x] += size_[y];
    }
    ll size(int x){
        x = find(x);
        return size_[x];
    }
    bool same(int x,int y){
        return find(x) == find(y);
    }
};


int main(){
    int n,m;
    cin >> n >> m;
    vector<ll> v(n);
    rep(i,n)cin >> v[i];
    vector<bool> flag(m);
    vector<pair<ll,pair<int,int> > > gs;
    vector<vector<pair<ll,int > > >g(n);
    vector<vector<ll> >  sm(n);
    rep(i,n){
        sm[i].push_back(v[i]);
    }
    rep(i,m){
        int a,b;
        ll x;
        cin >> a >> b >> x;
        a--;b--;
        gs.push_back(MP(x,MP(a,b)));
        g[a].push_back(MP(x,b));
        g[b].push_back(MP(x,a));
    }
    UnionFind uf(3*n);
    rep(i,n){
        uf.size_[i] = v[i];
    }
    sort(gs.begin(),gs.end());
    int id = 0;
    for(auto x:gs){
        int s = x.second.first;
        int t = x.second.second;
        ll w = x.first;
        //cerr << s << " " <<t <<  " " << uf.size(s) << " " << uf.size(t) << endl;
            
            uf.unite(s,t);
            ll tmp = uf.size(s);
            sm[s].push_back(tmp);
            sm[t].push_back(tmp);
        
        id++;
    }
    int ans = 0;
    set<int>st;
    for(int i=m-1;i>=0;i--){
        int s = gs[i].second.first;
        int t = gs[i].second.second;
        if(st.count(s)==1)continue;
        ll w = gs[i].first;
        if(sm[s][(int)sm[s].size()-1]<w){
            if(flag[i]==0){
                sm[s].pop_back();
                sm[t].pop_back();
                //cerr << s << " " << t  << " " << sm[s][(int)sm[s].size()-1] << endl;
                ans++;
            }else{
                sm[s].pop_back();
                sm[t].pop_back();

                //cerr << s << " " << t  << " " << sm[s][(int)sm[s].size()-1] << endl;
                ans++;
            }
        }else{
            queue<int> q;
            q.push(s);
            q.push(t);
            st.insert(s);
            st.insert(t);
            vector<bool> reached(n);
            reached[s] = 1;
            reached[t] = 1;
            while(!q.empty()){
                int x = q.front();
                q.pop();
                for(auto pp:g[x]){
                    if(pp.first<=w){
                        if(!reached[pp.second]){
                            q.push(pp.second);
                            reached[pp.second] = 1;
                            st.insert(pp.second);
                        }
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 27376