/*input
4 4
2 3 5 7
1 2 7
1 3 9
2 3 12
3 4 18
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i, j, k)  for(int i = j; i <  k; ++i)
#define RREP(i, j, k) for(int i = j; i >= k; --i)
#define F first
#define S second
#define mp make_pair
#define pb emplace_back
#define PII pair<int , int>
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie(0) , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define MAX 100009
#define INF 0x3f3f3f3f

struct djs{
    int x[MAX] , v[MAX];
    void init(){ REP(i , 0 , MAX) x[i] = i; }
    int Find(int now){ return x[now] == now ? now : x[now] = Find(x[now]); }
    void Union(int a , int b){
        a = Find(a) , b = Find(b);
        x[a] = b;
        v[b] += v[a];
    }
    int operator[](int now){ return Find(now); }
} ds;

int n , m , e[MAX][3] , x[MAX] , in[MAX] , s[MAX];
int cut[MAX][2] , is[MAX];
int cmp(int a , int b){ return e[a][2] < e[b][2]; }
int32_t main(){
    IOS;
    cin >> n >> m;
    REP(i , 1 , n + 1) cin >> x[i];
    REP(i , 1 , m + 1) REP(j , 0 , 3) cin >> e[i][j];
    REP(i , 1 , m + 1) s[i] = i;
    sort(s + 1 , s + 1 + m , cmp);
    
    ds.init();
    REP(i , 1 , n + 1) ds.v[i] = x[i];

    REP(idx , 1 , m + 1){ int i = s[idx];
        int v1 = e[i][0] , v2 = e[i][1];

        if(ds[v1] != ds[v2]){
            is[i] = 1;
            cut[i][0] = ds.v[ds[v1]];
            cut[i][1] = ds.v[ds[v2]];
            ds.Union(v1 , v2);
        }
    // REP(i , 1 , n + 1) cout << ds.v[i] << " "; cout << endl;
    }
    int ans = 0;
    RREP(idx , m , 1){ int i = s[idx];
        int v1 = e[i][0] , v2 = e[i][1];
        // DB4("edge " , e[i][2] , "vs = " , ds.v[ds[v1]]);
        if(ds.v[ds[v1]] < e[i][2]){
            ans ++;
            if(is[i]){
                // DBGG("delete" , "");
                ds.x[v1] = v1 , ds.v[v1] = cut[i][0];
                ds.x[v2] = v2 , ds.v[v2] = cut[i][1];
            }
        }
    //     cout << "\t\t\t";
    // REP(i , 1 , n + 1) cout << ds.v[i] << " "; cout << endl;
    }
    cout << ans << endl;
    return 0;
}