#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;

int N,M;
int X[101010],Y[101010];
int A[101010],B[101010];
vector<pair<ll,int>> E;
vector<vector<pair<int,int>>> G(101010);
ll sum[101010];

int par[101010];
int rnk[101010];

void init(){
  for(int i=0;i<N;i++){
    par[i]=i;
    rnk[i]=0;
    sum[i]=X[i];
  }
}

int find(int x){
  if (par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x, int y){
  x = find(x);
  y = find(y);
  if (x == y) return;

  if (rnk[x] < rnk[y]){
    par[x] = y;
    sum[y]+=sum[x];
  }else{
    par[y] = x;
    sum[x]+=sum[y];
    if (rnk[x] == rnk[y]) rnk[x]++;
  }
}

int use[101010];

void dfs(int v,int ma){
  for(auto p:G[v]){
    int e=p.second;
    if(use[e]==0&&Y[e]<=ma){
      use[e]=1;
      dfs(p.first,ma);
    }
  }
}

int main(){
  cin>>N>>M;
  rep(i,N) cin>>X[i];
  init();
  rep(i,M){
    cin>>A[i]>>B[i]>>Y[i]; A[i]--,B[i]--;
    G[A[i]].push_back({B[i],i});
    G[B[i]].push_back({A[i],i});
    E.push_back({Y[i],i});
  }
  sort(E.begin(),E.end());
  stack<int> st;
  for(auto p:E){
    int i=p.second,pa=find(A[i]),pb=find(B[i]);
    if(pa==pb){
      if(sum[pa]>=Y[i]) st.push(i);
    }else{
      if(sum[pa]+sum[pb]>=Y[i]) st.push(i);
    }
    unite(A[i],B[i]);
  }
  while(st.size()){
    int i=st.top(); st.pop();
    use[i]=1;
    dfs(A[i],Y[i]);
    dfs(B[i],Y[i]);
  }
  int ans=M;
  rep(i,M) ans-=use[i];
  cout<<ans<<endl;
  return 0;
}
