#include <bits/stdc++.h>
using namespace std;
template <typename T>
void _dbg(const char* _s, T _h) {
  cerr << _s << " = " << _h << "\n";
}
template <typename T, typename... Ts>
void _dbg(const char* _s, T _h, Ts... _t) {
  int _b = 0;
  while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',') cerr << *_s++;
  cerr << " = " << _h << ",";
  _dbg(_s + 1, _t...);
}
using ll = long long;
const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;
int n, m;
ll cnt = 0;
ll x[MAXN];
bool used[MAXN];
vector<pair<int, ll> > g[MAXN];
bool read() {
  if (!(cin >> n >> m)) return false;
  for (ll i = 0; i < (ll)(n); ++i) cin >> x[i];
  for (ll i = 0; i < (ll)(m); ++i) {
    int u, v;
    ll y;
    cin >> u >> v >> y;
    g[u - 1].emplace_back(make_pair(v - 1, y));
    g[v - 1].emplace_back(make_pair(u - 1, y));
  }
  return true;
}
vector<int> cur;
void dfs1(int v) {
  used[v] = true;
  cnt += x[v];
  cur.emplace_back(v);
  for (auto to : g[v])
    if (!used[to.first]) dfs1(to.first);
}
void solve() {
  int ans = 0;
  while (true) {
    fill(used, used + n, false);
    bool flag = false;
    for (ll i = 0; i < (ll)(n); ++i)
      if (!used[i]) {
        cnt = 0;
        cur.clear();
        dfs1(i);
        for (auto& v : cur) {
          vector<pair<int, ll> > nvec;
          for (auto& e : g[v]) {
            if (e.second <= cnt)
              nvec.emplace_back(e);
            else
              ++ans, flag = true;
          }
          g[v].swap(nvec);
        }
      }
    if (!flag) break;
  }
  cout << ans / 2 << '\n';
}
int main() {
  cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  while (read()) solve();
  return 0;
}
