#include <bits/stdc++.h>
using namespace std;
const int nmax = 100005;
struct edg {
  int a, b, c;
} v[nmax];
long long sum[nmax], w[nmax];
int tt[2 * nmax], rg[2 * nmax], apm[nmax], mare[nmax];
int n, m, i, j, ans;
vector<int> ad[nmax];
bool comp(edg unu, edg doi) { return unu.c < doi.c; }
int finds(int x) {
  while (x != tt[x]) x = tt[x];
  return x;
}
void unite(int A, int B) {
  if (rg[A] < rg[B]) swap(A, B);
  tt[B] = A;
  sum[A] += sum[B];
  rg[A] += rg[B];
}
void reet(int x, int R, int bad) {
  tt[x] = R;
  sum[R] += 1LL * w[x];
  for (int i = 0; i < ad[x].size(); i++)
    if (ad[x][i] != bad) {
      if (tt[ad[x][i]] != R) reet(ad[x][i], R, bad);
    } else {
      swap(ad[x][i], ad[x].back());
      ad[x].pop_back();
      i--;
    }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (i = 1; i <= n; i++) cin >> w[i];
  for (i = 1; i <= m; i++) {
    cin >> v[i].a >> v[i].b >> v[i].c;
  }
  sort(v + 1, v + m + 1, comp);
  for (i = 1; i <= n; i++) sum[i] = w[i], tt[i] = i, rg[i] = 1;
  for (i = 1; i <= m; i++) {
    if (finds(v[i].a) != finds(v[i].b)) {
      if (rg[finds(v[i].a)] >= rg[finds(v[i].b)])
        mare[i] = v[i].a;
      else
        mare[i] = v[i].b;
      unite(finds(v[i].a), finds(v[i].b));
      apm[i] = 1;
      ad[v[i].a].push_back(v[i].b);
      ad[v[i].b].push_back(v[i].a);
    }
  }
  long long sumtot;
  for (i = m; i >= 1; i--) {
    if (v[i].a == mare[i]) swap(v[i].a, v[i].b);
    if (apm[i] && sum[finds(v[i].a)] < v[i].c) {
      sumtot = sum[finds(v[i].a)];
      sum[v[i].a] = 0;
      reet(v[i].a, v[i].a, v[i].b);
      sum[finds(v[i].b)] = sumtot - sum[v[i].a];
    }
  }
  ans = m;
  for (i = 1; i <= m; i++)
    if (finds(v[i].a) == finds(v[i].b) && sum[finds(v[i].a)] >= v[i].c) ans--;
  cout << ans;
  return 0;
}
