#include <bits/stdc++.h>
using namespace std;
#define int long long
    



signed main(){
    int n,m;
    cin >> n >>m;
    int score[n+1+m];
    int oya[n+1+m]={};
    vector<int> kodomo[n+1+m];
    int x;
    for(int i=1;i<=n;i++){
        cin >> score[i];
       
    }
    pair<int,pair<int,int>> hen[m];
    int a,b,y;
    for(int i=0;i<m;i++){
        cin >> a >> b>>y;
        hen[i]=make_pair(y,make_pair(a,b));
    }
    sort(hen,hen+m);
    //cerr << hen[0].first<<hen[0].second.first;
    queue<int> que1,que2;
    
    for(int i=0;i<m;i++){
        a = hen[i].second.first;
        b= hen[i].second.second;
        que1.push(a);
        que2.push(b);
        while(oya[a]!=0){
            a=oya[a];
            que1.push(a);
        }
         while(oya[b]!=0){
            b=oya[b];
            que2.push(b);
        }
        if(a!=b){
            score[n+i+1]=score[a]+score[b];
            kodomo[n+i+1].push_back(a);
            kodomo[n+i+1].push_back(b);
        }else{
             score[n+i+1]=score[a];
            kodomo[n+i+1].push_back(a);
        }
        while(!que1.empty()){
            a =que1.front();
            que1.pop();
            oya[a]=n+i+1;
        }
        while(!que2.empty()){
            b =que2.front();
            que2.pop();
            oya[b]=n+i+1;
        }
    }
    int ans=0,k;
    que1.push(n+m);
    while(!que1.empty()){
        k=que1.front();
        que1.pop();
        if(score[k]<hen[k-n-1].first){
            ans++;
            for(int i=0;i<kodomo[k].size();i++){
               if(kodomo[k][i]>n) que1.push(kodomo[k][i]);
            }
        }
    }
    cout << ans;

    

    return 0;
}