#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define mp(a,b) make_pair(a,b)
#define pi acos(-1)
#define pii pair<int,int>
#define pb push_back
#define lowbit(x) ((x)&(-x))
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int maxn = 1e5 + 10;
const int maxm = 1e6 + 10;
const ll mod =  998244353;

int a[maxn],fa[maxn];

struct edge {
    int u,v,w;
    bool operator < (const edge &x)const {
        return w < x.w;
    }
}e[maxn];

int findd(int x) {
    return x == fa[x] ? x : fa[x] = findd(fa[x]);
}

struct node {
    int num,mxedge,ok;
    ll sum;
}blo[maxn];

int main() {
#ifdef local
    freopen("data.txt", "r", stdin);
//    freopen("data.txt", "w", stdout);
#endif
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i = 1; i <= n; i++) scanf("%d",&a[i]);
    for(int i = 1; i <= m; i++) scanf("%d%d%d",&e[i].u,&e[i].v,&e[i].w);
    sort(e + 1, e + 1 + m);
    for(int i = 1; i <= n; i++) {
        fa[i] = i;
        blo[i].num = blo[i].mxedge = blo[i].ok = 0;
        blo[i].sum = a[i];
    }
    int ans = 0;
    for(int i = 1; i <= m; i++) {
        int u = e[i].u, v = e[i].v, w = e[i].w;
        int fu = findd(u), fv = findd(v);
        if(fu == fv) {
            blo[fu].num++;
            blo[fu].mxedge = max(blo[fu].mxedge, w);
        } else {
            fa[fv] = fu;
            blo[fu].num += blo[fv].num + 1;
            blo[fu].mxedge = max(max(blo[fu].mxedge, blo[fv].mxedge), w);
            blo[fu].sum += blo[fv].sum;
            blo[fu].ok += blo[fv].ok;
        }

        if(blo[fu].sum >= blo[fu].mxedge) {
            ans += blo[fu].num - blo[fu].ok;
            blo[fu].ok = blo[fu].num;
        }
    }
    printf("%d\n",m - ans);
    return 0;
}
