#include <bits/stdc++.h>
using i64 = long long;
template <class T = int>
class UF {
  T *par;

 public:
  UF(T n) : par(new T[n]) {
    for (T i = 0; i < n; i++) par[i] = i;
  }
  ~UF() { delete[] par; }
  T root(T x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  bool same(T x, T y) { return root(x) == root(y); }
  void unite(T x, T y) {
    x = root(x);
    y = root(y);
    if (x != y) par[x] = y;
  }
};
std::vector<int> p;
std::vector<std::deque<std::pair<int, i64>>> tt;
int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<i64> x(n);
  i64 sum = 0;
  for (int i = 0; i < n; i++) {
    std::cin >> x[i];
    sum += x[i];
  }
  std::set<std::pair<i64, std::pair<int, int>>> ss;
  std::vector<std::deque<std::pair<int, i64>>> g(n);
  std::vector<std::pair<i64, std::pair<int, int>>> es;
  for (int i = 0; i < n; i++) {
    i64 a, b, y;
    std::cin >> a >> b >> y;
    a--;
    b--;
    g[a].emplace_back(b, y);
    g[b].emplace_back(a, y);
    ss.insert({y, {a, b}});
    es.push_back({y, {a, b}});
  }
  tt.resize(n);
  UF<> uft(n);
  while (!ss.empty()) {
    auto it = ss.begin();
    auto a = it->second.first, b = it->second.second;
    auto y = it->first;
    if (!uft.same(a, b)) {
      uft.unite(a, b);
      if (y <= sum) {
        tt[a].emplace_back(b, y);
        tt[b].emplace_back(a, y);
      }
    }
    ss.erase(it);
  }
  UF<> uft2(n);
  p.resize(n);
  for (int i = 0; i < n; i++) p[i] = -1;
  for (int i = 0; i < n; i++) {
    if (p[i] < 0) {
      std::deque<int> qq{i};
      while (!qq.empty()) {
        auto v = qq.front();
        qq.pop_front();
        for (auto to : tt[v]) {
          if (uft2.same(v, to.first)) continue;
          uft2.unite(v, to.first);
          qq.push_back(to.first);
        }
      }
    }
  }
  std::vector<i64> aa(n);
  for (int i = 0; i < n; i++) {
    aa[uft2.root(i)] += x[i];
  }
  int ret = 0;
  for (auto &el : es) {
    if (el.first > aa[uft2.root(el.second.first)]) ret++;
  }
  std::cout << ret << std::endl;
  return 0;
}
