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

using namespace std;

#define N 100001

int dsu[N],numUnsat[N];
long long sum[N];
int f(int x) {
  return dsu[x] ==x ? x : dsu[x] = f(dsu[x]);
}
void merge(int &ret,int x,int y,int wei) {
  x = f(x),y = f(y);
  if(x==y) {
    ++numUnsat[x];
  } else {
    sum[x] += sum[y];
    dsu[y] = x;
    numUnsat[x] = numUnsat[x] + numUnsat[y] + 1;
  }
  if(sum[x]>=wei) {
    ret += numUnsat[x];
    numUnsat[x] = 0;
  }
}
void solve() {
  int n,m;scanf("%d %d",&n,&m);
  pair<int,pair<int,int> > edge[N];
  for(int i=1;i<=n;++i) {
    int x;scanf("%d",&x);
    dsu[i] = i;
    numUnsat[i] = 0;
    sum[i] = x;
  }
  for(int i=0;i<m;++i) {
    int a,b,w;scanf("%d %d %d ",&a,&b,&w);
    edge[i] = make_pair(w,make_pair(a,b));
  }
  sort(edge,edge+m);
  int ret = 0;
  for(int i=0;i<m;++i) {
    merge(ret, edge[i].second.first,edge[i].second.second,edge[i].first);
  }
  printf("%d\n",m-ret);
}

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