#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct node
{
    int u,v;
    ll w;
    bool operator<(const node&o)
    {
        return w<o.w;
    }
}e[100005];
bool cmp(node p1,node p2)
{
    return p1.w>p2.w;
}
int n,m,cot=0,f[100005],cnt=0,d[100005];
priority_queue<ll,vector<ll>,greater<int> >q;
vector<pair<int,ll> >v[100005];
ll sum=0,a[100005];
bool vis[100005];
int get_fa(int x)
{
    return f[x]==x?x:f[x]=get_fa(f[x]);
}
ll kruskal()
{
    for(int i=1;i<=n;i++) f[i]=i;
    ll ans=0;
    for(int i=1;i<=m;i++)
    {
        int fu=get_fa(e[i].u),fv=get_fa(e[i].v);
        if(fu==fv)
        {
            q.push(e[i].v);
            continue;
        }
        f[fu]=fv;
        e[++cot]=e[i];
        ans=max(ans,e[i].w);
    }
    return ans;
}
int check(int x)
{
    return 0;
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]),sum+=a[i];
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d%lld",&e[i].u,&e[i].v,&e[i].w);
        if(e[i].u>e[i].v) swap(e[i].u,e[i].v);
    }
    sort(e+1,e+1+n);
    ll res=kruskal(),ans;
    if(res<=sum)
    {
        ans=n-1;
        cout<<1<<endl;
        while(!q.empty()&&q.top()<=sum) ans++,q.pop();
    }
    else
    {
        ans=n-1;
        sort(e+1,e+1+cot);
        int i;
        for(i=1;i<=cot;i++)
            if(e[i].w>sum) ans--;
    }
    printf("%lld\n",ans);
}
