#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<set<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(v, y);
      g[v].emplace(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());
  for (auto &e : forest) {
    int u = get<1>(e), v = get<2>(e);
    const auto y = get<0>(e);
    if (sum[root[u]] < y) {
      set<int> inQ;
      vector<int> qu, qv;
      qu.emplace_back(u);
      inQ.emplace(u);
      qv.emplace_back(v);
      inQ.emplace(v);
      for (int i = 0; i < qu.size() && i < qv.size(); ++i) {
        int x = qu[i];
        for (auto &e : g[x])
          if (!inQ.count(e.first)) {
            qu.emplace_back(e.first);
            inQ.emplace(e.first);
          }
        x = qv[i];
        for (auto &e : g[x])
          if (!inQ.count(e.first)) {
            qv.emplace_back(e.first);
            inQ.emplace(e.first);
          }
      }
      if (qu.size() < qv.size()) {
        swap(u, v);
        swap(qu, qv);
      }
      int r = root[u];
      for (auto &p : qv) {
        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;
}
