#include <bits/stdc++.h>
#define N 100010
using namespace std;
typedef long long ll;
inline ll read()
{
  ll p=0; ll f=1; char ch=getchar();
  while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();}
  while(ch>='0' && ch<='9'){p=p*10+(ch-'0'); ch=getchar();}
  return p*f;
}
struct node
{
  ll x,y,d;
  node(){}
  node(ll _x,ll _y,ll _d){x=_x; y=_y; d=_d;}
}edge[N],a[N]; ll len;
bool cmp(const node &x,const node &y)
{
  return x.d<y.d;
}
ll val[N],fa[N],siz[N];
ll ffind(ll x){return (fa[x]==x) ? fa[x] : ffind(fa[x]);}
int main()
{
  ll n=read(),m=read();
  for(ll i=1;i<=n;i++) val[i] = read() , fa[i] = i , siz[i] = 1;
  for(ll i=1;i<=m;i++){a[i].x = read(); a[i].y = read(); a[i].d = read();}
  len = 0; sort(a+1,a+m+1,cmp);
  for(ll i=1;i<=m;i++)
  {
    ll x = ffind(a[i].x); ll y = ffind(a[i].y);
    if(x!=y)
    {
      if(siz[x] < siz[y]) swap(x,y);
      len++; edge[len] = node(x,y,a[i].d);
      val[x] += val[y]; siz[x] += siz[y]; fa[y] = x;
    }
  }
  for(ll i=len;i>=1;i--)
  {
    ll x = edge[i].x; ll y = edge[i].y;
    if(edge[i].d > val[ffind(x)])
    {
      fa[y] = y;
      while(x!=fa[x]) val[x] -= val[y],x=fa[x]; val[x] -= val[y];
    }
  }ll s = 0;
  for(ll i=1;i<=m;i++)
  {
    ll x = ffind(a[i].x); ll y = ffind(a[i].y);
    if(x==y && val[x]>=a[i].d) s++;
  }
  return printf("%lld\n",m-s),0;
}