#include <bits/stdc++.h>
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll mod = 1e9 + 7;
const double PI = acos(-1.0);
vector<P> graph[100005];
vector<bool> used(100005);
vector<bool> removed(100005);
vector<bool> used2(100005);
vector<ll> x(100005), y(100005);
priority_queue<P> que;
ll sum;
vector<int> usedp;
void dfs(int s) {
  used[s] = true;
  usedp.push_back(s);
  sum += x[s];
  for (auto e : graph[s]) {
    int i = e.second;
    if (!removed[i]) {
      que.emplace(y[e.second], i);
      if (!used[e.first]) {
        dfs(e.first);
      }
    }
  }
}
void clearused() {
  for (auto e : usedp) {
    used[e] = false;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < (int)(n); i++) {
    cin >> x[i + 1];
  }
  for (int i = 0; i < (int)(m); i++) {
    int a, b;
    cin >> a >> b;
    graph[a].emplace_back(b, i);
    graph[b].emplace_back(a, i);
    cin >> y[i];
  }
  for (int i = 1; i <= n; i++) {
    if (used2[i]) continue;
    while (true) {
      sum = 0;
      clearused();
      usedp.resize(0);
      dfs(i);
      bool flag = false;
      while (!que.empty()) {
        P p = que.top();
        que.pop();
        if (p.first > sum) {
          removed[p.second] = true;
          flag = true;
        } else {
          while (!que.empty()) {
            que.pop();
          }
        }
      }
      if (!flag) {
        for (auto e : usedp) {
          used2[e] = true;
        }
        break;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < m; i++) {
    if (removed[i]) {
      ans++;
    }
  }
  cout << ans << endl;
}
