#include <bits/stdc++.h>
using namespace std;
int par[101010];
int ranki[101010];
long long weigh[101010];
long long loop;
int info[101010][5];
void init(int n) {
  for (int i = 0; i < n; i++) {
    par[i] = i;
    ranki[i] = 0;
  }
}
int find(int x) {
  if (par[x] == x)
    return x;
  else
    return par[x] = find(par[x]);
}
void unite(int x, int y) {
  int x0 = x, y0 = y;
  x = find(x);
  y = find(y);
  if (x == y) {
    info[loop][0] = 0;
    info[loop][1] = x;
    info[loop][2] = weigh[x];
    info[loop][3] = y;
    info[loop][4] = weigh[y];
    return;
  } else {
    info[loop][0] = 1;
    info[loop][1] = x;
    info[loop][2] = weigh[x];
    info[loop][3] = y;
    info[loop][4] = weigh[y];
    if (ranki[x] < ranki[y]) {
      par[x] = y;
      weigh[y] = weigh[x] + weigh[y];
      weigh[x] = weigh[y];
    } else {
      par[y] = x;
      if (ranki[x] == ranki[y]) ranki[x]++;
      weigh[x] = weigh[x] + weigh[y];
      weigh[y] = weigh[x];
    }
  }
}
bool same(int x, int y) { return find(x) == find(y); }
int main() {
  long long i, j;
  long long n, m;
  cin >> n >> m;
  init(n + 10);
  long long x[n];
  for (i = 0; i < n; i++) {
    cin >> x[i];
    weigh[i] = x[i];
  }
  vector<pair<int, pair<int, int> > > e;
  int a, b, y;
  for (i = 0; i < m; i++) {
    cin >> a >> b >> y;
    e.push_back(make_pair(y, make_pair(a - 1, b - 1)));
  }
  sort(e.begin(), e.end());
  loop = 0;
  for (i = 0; i < m; i++) {
    unite(e[i].second.first, e[i].second.second);
    loop++;
  }
  loop--;
  long long ans = 0;
  for (i = loop; i >= 0; i--) {
    if (e[i].first > weigh[info[i][1]]) {
      ans++;
      if (info[i][0] == 1) {
        weigh[info[i][1]] = info[i][2];
        weigh[info[i][3]] = info[i][4];
      }
    }
  }
  cout << ans << endl;
  return 0;
}
