#include<bits/stdc++.h>
#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 repd(i,a,b) for(int i=a;i>=b;--i)
#define rvc(i,S) for(int i=0;i<(int)S.size();++i)
#define fore(i,x) for(int i = head[x] ; i ; i = e[i].next)
#define mp make_pair
#define pb push_back
#define maxn 200005
#define ll long long 
#define fi first
#define se second
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
int fa[maxn];
int getfa(int x)
{if(fa[x]==x) return x;
 fa[x]=getfa(fa[x]);
 return fa[x];
}
struct Edge
{ int x,y,len;
};vector<Edge> g;
ll val[maxn];
int cut[maxn];
bool cmp(Edge A,Edge B)
{return A.len<B.len;}
int n,m;
int main()
{cin>>n>>m;rep(i,1,n) cin>>val[i];
 rep(i,1,n) fa[i]=i;
 rep(i,1,m)
  {int x,y,len; scanf("%d%d%d",&x,&y,&len);
   g.pb((Edge){x,y,len});
  }
  sort(g.begin(),g.end(),cmp);
  rep(i,0,m-1)
  {int x=g[i].x,y=g[i].y,len=g[i].len;
   x=getfa(x);y=getfa(y);
   if(x!=y) 
     {val[y]+=val[x];
      fa[x]=y;
      cut[y]+=cut[x];
	 }
   cut[y]++;
     if(val[y]>=len) cut[y]=0;
  }
  int ans=0;
  rep(i,1,n) if(getfa(i)==i) ans+=cut[i];
  cout<<ans<<endl;
return 0;	
}