#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long i, j, k, n, m, h, w, a, b, sum = 0, ans = 0;
  scanf("%lld%lld", &n, &m);
  long long x[n];
  pair<long long, pair<long long, long long> > 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;
  long long uf[n], now[n];
  long long 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) {
    long long 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;
}
