#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <iostream>
#include <cassert>
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define per(i, a, b) for (int i = a; i >= b; --i)
#define rvc(i, S) for (int i = 0; i < S.size(); ++i)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;

typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> VI;

const int N=100005;
int n,m,fa[N],cnt[N];
LL sum[N];

struct edge{
    int u,v,w;

    bool operator <(const edge &b) const{
        return w<b.w;
    }
} ed[N];

int Find(int x){
    if(fa[x]==x)return x;
    int y=Find(fa[x]);
    sum[y]+=sum[x];
    cnt[y]+=cnt[x];
    sum[x]=cnt[x]=0;
    return fa[x]=y;
}

int main(){
    cin>>n>>m;
    rep(i,1,n){
        cin>>sum[i];
        fa[i]=i;
        cnt[i]=0;
    }
    rep(i,1,m)
        cin>>ed[i].u>>ed[i].v>>ed[i].w;
    sort(ed+1,ed+m+1);
    int ans=0;
    rep(i,1,m){
        int u=Find(ed[i].u),v=Find(ed[i].v);
        if(u!=v){
            fa[u]=v;
            sum[v]+=sum[u];
            cnt[v]+=cnt[u]+1;
            cnt[u]=sum[u]=0;
            if(sum[v]>=ed[i].w){
                ans+=cnt[v];
                cnt[v]=0;
            }
        }else{
            ++cnt[u];
            if(sum[u]>=ed[i].w){
                ans+=cnt[u];
                cnt[u]=0;
            }
        }
    }
    cout<<m-ans<<endl;
    return 0;
}
