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

 public:
  UF(T n) : par(new T[n]), s(std::vector<std::deque<T>>(n)) {
    for (T i = 0; i < n; i++) {
      par[i] = i;
      s[i].push_back(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;
      for (auto v : s[x]) s[y].push_back(v);
      s[x].clear();
    }
  }
  std::deque<T> get(T x) { return s[root(x)]; }
};
int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<i64> w(n);
  for (int i = 0; i < n; i++) {
    std::cin >> w[i];
  }
  std::vector<std::pair<i64, std::pair<int, int>>> es;
  for (int i = 0; i < m; i++) {
    int a, b;
    i64 y;
    std::cin >> a >> b >> y;
    a--;
    b--;
    es.push_back({y, {a, b}});
  }
  std::sort(es.begin(), es.end());
  UF<> uft(n);
  std::vector<bool> cand(m), done(m);
  std::vector<std::deque<int>> r(m);
  for (int i = 0; i < m; i++) {
    auto a = es[i].second.first, b = es[i].second.second;
    auto y = es[i].first;
    auto xx = w[uft.root(a)] + (uft.same(a, b) ? 0 : w[uft.root(b)]);
    uft.unite(a, b);
    w[uft.root(a)] = xx;
    if (y <= xx) {
      cand[i] = true;
      r[i] = uft.get(i);
    }
  }
  int ret = 0;
  for (int i = m - 1; i >= 0; i--) {
    if (done[i]) continue;
    if (!cand[i]) {
      ret++;
      continue;
    }
    for (auto v : r[i]) done[v] = true;
  }
  std::cout << ret << std::endl;
  return 0;
}
