#include <bits/stdc++.h>
using namespace std;
template <class C>
int size(const C &c) {
  return c.size();
}
template <class T, class... U>
bool chmin(T &a, const U &...bs) {
  const T b(bs...);
  if (a <= b) return false;
  a = b;
  return true;
}
template <class T, class... U>
bool chmax(T &a, const U &...bs) {
  const T b(bs...);
  if (a >= b) return false;
  a = b;
  return true;
}
struct UnionFind {
  vector<int> par;
  int n, cnt;
  UnionFind(const int &x = 0) { init(x); }
  void init(const int &x) { par.assign(cnt = n = x, -1); }
  inline int find(const int &x) {
    return par[x] < 0 ? x : par[x] = find(par[x]);
  }
  inline bool same(const int &x, const int &y) { return find(x) == find(y); }
  inline bool unite(int x, int y) {
    if ((x = find(x)) == (y = find(y))) return false;
    --cnt;
    if (par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }
  inline int count() const { return cnt; }
  inline int count(int x) { return -par[find(x)]; }
};
bool solve() {
  int n, m;
  cin >> n >> m;
  vector<long long> x(n);
  UnionFind uf(n);
  for (int i = (int)(0); i < (int)(n); ++i) cin >> x[i];
  vector<tuple<long long, int, int>> es;
  for (int i = (int)(0); i < (int)(m); ++i) {
    int a, b;
    long long y;
    cin >> a >> b >> y;
    --a;
    --b;
    es.emplace_back(y, a, b);
  }
  sort(begin(es), end(es));
  vector<tuple<long long, int, int>> forest;
  vector<vector<pair<int, long long>>> g(n);
  for (auto &e : es) {
    const auto u = get<1>(e), v = get<2>(e);
    const auto y = get<0>(e);
    if (uf.unite(u, v)) {
      forest.push_back(e);
      g[u].emplace_back(v, y);
      g[v].emplace_back(u, y);
    }
  }
  vector<int> root(n);
  vector<int> sum(n);
  for (int i = (int)(0); i < (int)(n); ++i) sum[0] += x[i];
  sort((forest).rbegin(), (forest).rend());
  set<pair<int, int>> deleted;
  for (auto &e : forest) {
    int u = get<1>(e), v = get<2>(e);
    const auto y = get<0>(e);
    if (sum[root[u]] < y) {
      deleted.emplace(u, v);
      set<int> cu, cv;
      vector<pair<int, int>> qu, qv;
      qu.emplace_back(u, 0);
      cu.emplace(u);
      qv.emplace_back(v, 0);
      cv.emplace(v);
      auto process = [&](vector<pair<int, int>> &q, set<int> &c) -> bool {
        while (true) {
          if (q.empty()) return false;
          const auto e = q.back();
          q.pop_back();
          if (e.second >= g[e.first].size()) {
            continue;
          }
          q.emplace_back(e.first, e.second + 1);
          const auto to = g[e.first][e.second].first;
          if (deleted.count(minmax(to, e.first))) continue;
          if (c.count(to)) continue;
          c.emplace(to);
          q.emplace_back(to, 0);
          return true;
        }
      };
      while (true) {
        if (!process(qu, cu) || !process(qv, cv)) break;
      }
      if (cu.size() < cv.size()) {
        swap(u, v);
        swap(cu, cv);
      }
      int r = root[u];
      for (auto &p : cv) {
        sum[r] -= x[p];
        sum[v] += x[p];
        root[p] = v;
      }
    }
  }
  int res = m;
  for (auto &e : es) {
    const auto u = get<1>(e), v = get<2>(e);
    const auto y = get<0>(e);
    if (root[u] == root[v] && sum[root[u]] >= y) {
      --res;
    }
  }
  cout << res << endl;
  return true;
}
signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << std::fixed << std::setprecision(10);
  solve();
  return 0;
}
