#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <assert.h>

using namespace std;

#define N 100005

int dsu[N],ret[N];
long long W[N];
vector<int> edgeS[N];
bool isGoodEdge[N];

int f(int x) {
  if(x==dsu[x]) {
    return x;
  }
  return dsu[x] = f(dsu[x]);
}
void merge(int x,int y,int id,int wei) {
  x = f(x),y = f(y);
  if(x!=y) {
    if(edgeS[x].size()<edgeS[y].size()) {
      swap(x,y);
    }
    dsu[y] = x;
    W[x] += W[y];
    while(edgeS[y].size()>0) {
      edgeS[x].push_back(edgeS[y].back());
      edgeS[y].pop_back();
    }
  }
  edgeS[x].push_back(id);
  if(W[x]>=wei) {
    while(edgeS[x].size()>0) {
      isGoodEdge[edgeS[x].back()] = true;
      edgeS[x].pop_back();
    }
  }
}
void solve() {
  int n,m;
  scanf("%d %d",&n,&m);
  pair<int,pair<int,int> > edgeS[N];
  for(int i=1;i<=n;++i) {
    dsu[i] = i;
    scanf("%lld",&W[i]);
  }
  for(int i=0;i<m;++i) {
    scanf("%d %d %d",&edgeS[i].second.first,&edgeS[i].second.second,&edgeS[i].first);
  }
  sort(edgeS,edgeS+m);
  int R = 0;
  for(int i=0;i<m;++i) {
    int w = edgeS[i].first;
    int a = edgeS[i].second.first, b = edgeS[i].second.second;
    merge(a,b,i,w);
  }
  for(int i=0;i<m;++i) {
    if(isGoodEdge[i]) {
      ++R;
    }
  }
  printf("%d\n",m - R);
}

int main() {
  //freopen("input.txt","r",stdin);
  solve();
  return 0;
}
