#pragma gcc optimize("Ofast")

#include "bits/stdc++.h"
using namespace std;
typedef int64_t lld;
typedef pair<int,int> pii;
typedef pair<lld,lld> pll;
typedef pair<int,pll> pip;
typedef pair<pll,int> ppi;
typedef pair<lld,pll> plp;
typedef pair<pll,lld> ppl;
typedef pair<pll,pll> ppp;
template<typename T>
using maxHeap = priority_queue<T,vector<T>,less<T>>;
template<typename T>
using minHeap = priority_queue<T,vector<T>,greater<T>>;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define endl '\n'
#define jizz cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
inline void input(int &_x) {
    _x = 0;
    int _tmp = 1; char _tc = getchar();
    while((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
    if(_tc == '-') _tc = getchar(), _tmp = -1;
    while(_tc >= '0' && _tc <= '9') _x = _x*10+(_tc-48), _tc = getchar();
    _x *= _tmp;
}
inline void output(int _x) {
    char _buff[20]; int _f = 0;
    if(_x == 0)putchar('0');
    while(_x > 0)
    {
        _buff[_f++] = _x%10+'0';
        _x /= 10;
    }
    for(_f-=1; _f >= 0; _f--)
        putchar(_buff[_f]);
    putchar('\n');
}
template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}
template<class T1,class T2>
ostream& operator<<(ostream& out, pair<T1,T2> p) {
    return out << '(' << p.first << ", " << p.second << ')';
}
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) {
     return _out(s,c.begin(),c.end());
 }
#ifdef erd1
    #define pprint(x) cerr<<__PRETTY_FUNCTION__<<":"<<__LINE__<<" - "<<(#x)<<"="<<(x)<<endl
#else
    #define pprint(x)
#endif

// code starts here

struct node{
    node *L = 0, *R = 0, *P = 0;
    lld data, lt;
    node(int x){ data = lt = x; }
    inline void up(){
        lt = data;
        if(L)lt += L->lt;
        if(R)lt += R->lt;
    }
    node*& child(node *x){ return x==L?L:R; }
    void rotateR(){
        node *r = R;
        if(P)P->child(this) = r;
        r->P = P;
        R = r->L;
        if(R)R->P = this;
        r->L = this;
        P = r;
        up();
        r->up();
    }
    void rotateL(){
        node *l = L;
        if(P)P->child(this) = l;
        l->P = P;
        L = l->R;
        if(L)L->P = this;
        l->R = this;
        P = l;
        up();
        l->up();
    }
    inline void rotate(){ P->L==this?P->rotateL():P->rotateR(); }
    node* splay(){
        while(P){
            if(P->P) ((P->L==this)^(P->P->L==P)?this:P)->rotate();
            this->rotate();
        }
        return this;
    }
    node* getR(){
        node *x = this;
        while(x->L)x = x->L;
        return x -> splay();
    }
    node* mergeL(node *x){
        node *y = getR();
        if(!x)return y;
        y->L = x;
        x->P = y;
        y->up();
        return y;
    }
    void cut(){
        splay();
        if(L)L->P = NULL;
        if(R)R->P = NULL;
    }
    void print(string s = ""){
        if(L)L->print(s+" ");
        cout << s << data << endl;
        if(R)R->print(s+" ");
    }
};
vector<int> v, ge;
vector<bool> tE;
vector<pair<int, pii>> Es;
vector<pair<node*, node*>> pEs;
vector<node*> pVs;
signed main(){
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        v.pb(x);
    }
    for(int i = 0; i < n; i++)
        pVs.pb(new node(v[i]));
    for(int i = 0; i < m; i++){
        int a, b, x;
        cin >> a >> b >> x;a--;b--;
        Es.pb({x, {a, b}});
    }
    sort(all(Es));
    pEs.resize(m+1);
    tE.resize(m+1);
    for(int i = 0; i < m; i++){
        int a = Es[i].ss.ff, b = Es[i].ss.ss;
        pVs[a]->splay();
        pVs[b]->splay();
        if(pVs[a]->P) continue;
        tE[i] = true;
        pEs[i] = {new node(0), new node(0)};
        pEs[i].ff
            -> mergeL(pVs[a])
            -> mergeL(pEs[i].ss)
            -> mergeL(pVs[b]);
    }
    int ans = 0;
    for(int i = m-1; i >= 0; i--){
        int a = Es[i].ss.ff, b = Es[i].ss.ss;
        if(pVs[a]->splay()->lt >= Es[i].ff)continue;
        //cout << Es[i] << pVs[a]->lt << endl;
        //pVs[a] -> print();
        ans++;
        if(!tE[i])continue;
        pEs[i].ff->cut();
        node *l = pEs[i].ff->L, *r = pEs[i].ff->R;
        if(l&&r)r -> mergeL(l);
        pEs[i].ss->cut();
    }
    cout << ans << endl;
}


Measured memory_bytes: 18288