#include <stdio.h>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>
#include <functional>
typedef long long ll;
using namespace std;

int main(void) {
  ll i, j, k, n, m, h, w, a, b, sum = 0, ans = 0;
  scanf("%lld%lld", &n, &m);
  ll x[n];
  pair< ll, pair<ll, ll> > e[m];
  for(i = 0; i < n; ++i) scanf("%lld", &x[i]), sum += x[i];
  for(i = 0; i < m; ++i) {
    scanf("%lld%lld%lld", &e[i].second.first, &e[i].second.second, &e[i].first);
    e[i].second.first--, e[i].second.second--;
    if(e[i].first > sum) ++ans;
  }
  sort(e, e + m);
  if(!ans) {
    printf("0");
    return 0;
  }
  ans = 0;
  ll uf[n], now[n];
  ll num[n];
  for(i = 0; i < n; ++i) uf[i] = i, now[i] = x[i], num[i] = 0;
  for(i = 0; e[i].first <= sum; ++i) {
    ll ra = 0, rb = 0, na = e[i].second.first, nb = e[i].second.second, tmpa, tmpb;
    while(uf[na] != na) ra++, na = uf[na];
    while(uf[nb] != nb) rb++, nb = uf[nb];
    if(na != nb) {
      if(ra < rb) {
        uf[na] = nb, now[nb] += now[na], now[na] = 0;
        tmpa = now[nb], tmpb = nb;
        num[nb] += num[na], num[na] = 0;
      } else {
        uf[nb] = na, now[na] += now[nb], now[nb] = 0;
        tmpa = now[na], tmpb = na;
        num[na] += num[nb], num[nb] = 0;
      }
    } else tmpa = now[na], tmpb = na;
    if(tmpa >= e[i].first) ans += num[tmpb] + 1, num[tmpb] = 0;
    else num[tmpb]++;
  }
  printf("%lld", m - ans);
  return 0;
}