#include <bits/stdc++.h>
using namespace std;
struct UF {
  std::vector<int> par, dep, dat;
  vector<deque<long long int>> pre;
  UF(int n) {
    par.resize(n + 1), dep.resize(n + 1), dat.resize(n + 1);
    pre.resize(n + 1);
    init(n);
  }
  void init(int nu) {
    for (int iu = 0; iu <= nu; iu++) par[iu] = iu, dep[iu] = 0;
  }
  long long int get(long long int a) { return dat[find(a)]; }
  bool same(int xu, int yu) { return find(xu) == find(yu); }
  int find(int xu) { return (par[xu] == xu ? xu : find(par[xu])); }
  void unite(int xu, int yu) {
    xu = find(xu), yu = find(yu);
    if (xu == yu) return;
    if (dep[xu] < dep[yu]) {
      par[xu] = yu;
      dat[yu] += dat[xu];
      pre[yu].push_front(xu);
    } else {
      par[yu] = xu;
      dat[xu] += dat[yu];
      pre[xu].push_front(yu);
      if (dep[xu] == dep[yu]) dep[xu]++;
    }
  }
  void decompose(long long int a) {
    long long int parent = find(a);
    long long int t = pre[parent].front();
    pre[parent].pop_front();
    par[t] = t;
    dat[parent] -= dat[t];
  }
};
int main(int argc, char const *argv[]) {
  long long int n, m;
  std::cin >> n >> m;
  vector<long long int> x(n + 1);
  for (long long int i = 0; i < n; i++) std::cin >> x[i + 1];
  vector<vector<long long int>> e =
      vector<vector<long long int>>(m, vector<long long int>(3, 0));
  for (long long int i = 0; i < m; i++)
    scanf("%lld %lld %lld", &e[i][1], &e[i][2], &e[i][0]);
  sort((e).begin(), (e).end());
  UF uf(n + 1);
  for (long long int i = 1; i < n + 1; i++) uf.dat[i] = x[i];
  vector<vector<long long int>> br =
      vector<vector<long long int>>(m, vector<long long int>(2, 0));
  for (long long int i = 0; i < m; i++) {
    long long int a = e[i][1], b = e[i][2];
    if (!uf.same(a, b))
      br[i][0] = uf.get(a), br[i][1] = uf.get(b);
    else
      br[i][0] = -1, br[i][1] = uf.get(a);
    uf.unite(a, b);
  }
  set<long long int> lock;
  long long int ans = 0;
  for (int i = m - 1; i >= 0; i--) {
    if (lock.find(e[i][1]) != lock.end()) continue;
    if (br[i][0] == -1) {
      if (uf.get(e[i][1]) < e[i][0])
        ans++;
      else
        lock.insert(uf.find(e[i][1]));
    } else {
      if (uf.get(e[i][1]) < e[i][0]) {
        ans++;
        uf.decompose(e[i][1]);
      } else
        lock.insert(uf.find(e[i][1]));
    }
  }
  std::cout << ans << '\n';
  return 0;
}
