#include <bits/stdc++.h>
using namespace std;
class Edge {
 public:
  long long to;
  long long w;
};
class Edge2 {
 public:
  long long from, to, w;
  bool operator<(const Edge2 &e) const { return w < e.w; }
};
bool solve(long long N, long long now1, long long now2, long long nowW,
           long long maxi, const vector<long long> &W,
           const vector<vector<Edge>> &E, vector<long long> &maxW) {
  unordered_set<int> visited;
  queue<int> Q;
  Q.push(now1);
  Q.push(now2);
  visited.insert(now1);
  visited.insert(now2);
  long long sum = 0;
  while (!Q.empty()) {
    int now = Q.front();
    Q.pop();
    sum += W[now];
    for (auto &e : E[now]) {
      if (e.w > nowW) continue;
      if (visited.count(e.to)) continue;
      visited.insert(e.to);
      Q.push(e.to);
    }
  }
  if (sum >= nowW) {
    for (auto v : visited) maxW[v] = max(maxW[v], sum);
    return true;
  } else {
    return false;
  }
}
int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> W(N);
  for (int i = 0; i < (int)N; i++) cin >> W[i];
  vector<vector<Edge>> E(N);
  vector<Edge2> EE;
  long long sum = 0;
  for (int i = 0; i < (int)M; i++) {
    Edge e;
    long long from;
    cin >> from >> e.to >> e.w;
    from--;
    e.to--;
    E[from].push_back(e);
    swap(e.to, from);
    E[from].push_back(e);
    sum += e.w;
    EE.push_back((Edge2){from, e.to, e.w});
  }
  sort((EE).begin(), (EE).end());
  reverse((EE).begin(), (EE).end());
  vector<long long> maxW(N);
  for (int i = 0; i < (int)N; i++) maxW[i] = -1;
  for (__typeof((EE).begin()) it = (EE).begin(); it != (EE).end(); ++it) {
    solve(N, it->from, it->to, it->w, sum, W, E, maxW);
  }
  long long ans = 0;
  for (int i = 0; i < (int)N; i++) {
    for (auto &e : E[i]) {
      long long now1 = i, now2 = e.to;
      if (maxW[now1] >= e.w && maxW[now2] >= e.w) {
      } else {
        ans++;
      }
    }
  }
  cout << ans / 2 << endl;
  return 0;
}
