#include <bits/stdc++.h>
using namespace std;
int n, m, i, r1, r2, nr;
int ff[100005], r[100005], viz[100005], val[100005];
long long sum[100005];
vector<pair<int, int> > v[100005];
struct str {
  int x, y, c;
};
str w[100005];
int cmp(str a, str b) { return a.c < b.c; }
int rad(int x) {
  while (r[x] > 0) {
    x = r[x];
  }
  return x;
}
void dfs(int nod, int maxim) {
  for (int i = 0; i < v[nod].size(); i++) {
    int ind = v[nod][i].second;
    if (viz[ind] == 0 && w[ind].c <= maxim) {
      viz[ind] = 1;
      nr++;
      dfs(v[nod][i].first, maxim);
    }
  }
}
int main() {
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> val[i];
  }
  for (i = 1; i <= m; i++) {
    cin >> w[i].x >> w[i].y >> w[i].c;
  }
  sort(w + 1, w + m + 1, cmp);
  for (i = 1; i <= n; i++) {
    r[i] = -1;
    sum[i] = val[i];
  }
  for (i = 1; i <= m; i++) {
    r1 = rad(w[i].x);
    r2 = rad(w[i].y);
    if (r1 != r2) {
      if (r[r1] < r[r2]) {
        r[r1] += r[r2];
        r[r2] = r1;
        sum[r1] += sum[r2];
      } else {
        r[r2] += r[r1];
        r[r1] = r2;
        sum[r2] += sum[r1];
      }
    }
    if (sum[r1] >= w[i].c) {
      ff[i] = 1;
    }
  }
  for (i = 1; i <= m; i++) {
    v[w[i].x].push_back(make_pair(w[i].y, i));
    v[w[i].y].push_back(make_pair(w[i].x, i));
  }
  for (i = m; i >= 1; i--) {
    if (viz[i] == 0 && ff[i] == 1) {
      dfs(w[i].x, w[i].c);
    }
  }
  cout << m - nr;
  return 0;
}
