#include <bits/stdc++.h>
using namespace std;
class UnionFind {
 public:
  UnionFind(){};
  ~UnionFind(){};
  void init(int num_entries) {
    num_entries_ = num_entries;
    par_.resize(num_entries_);
    rank_.resize(num_entries_, 0);
    for (int i = 0; i < (int)(num_entries_); ++i) par_[i] = i;
  }
  int find(int x) {
    if (par_[x] == x)
      return x;
    else
      return par_[x] = find(par_[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rank_[x] < rank_[y])
      par_[x] = y;
    else {
      par_[y] = x;
      if (rank_[x] == rank_[y]) rank_[x]++;
    }
  }
  bool same(int x, int y) { return find(x) == find(y); }

 private:
  int num_entries_;
  std::vector<int> par_;
  std::vector<int> rank_;
};
int main(void) {
  cin.sync_with_stdio(false);
  long long N, M;
  cin >> N >> M;
  vector<long long> Xs(N);
  long long sum_of_x = 0;
  for (int n = 0; n < (int)(N); ++n) {
    cin >> Xs[n];
    sum_of_x += Xs[n];
  }
  int ans = 0;
  vector<pair<int, int>> edges(M);
  vector<long long> Ys(M);
  vector<char> deleted_edge(M);
  UnionFind uf;
  uf.init(N);
  for (int m = 0; m < (int)(M); ++m) {
    int a, b;
    long long y;
    cin >> a >> b >> y;
    --a;
    --b;
    edges[m] = make_pair(a, b);
    Ys[m] = y;
    if (y > sum_of_x) {
      ++ans;
      deleted_edge[m] = 1;
    } else {
      uf.unite(a, b);
    }
  }
  vector<long long> group_sum(N);
  for (int n = 0; n < (int)(N); ++n) {
    auto id = uf.find(n);
    group_sum[id] += Xs[n];
  }
  while (true) {
    bool ok = true;
    for (int m = 0; m < (int)(M); ++m) {
      if (deleted_edge[m]) continue;
      int a, b;
      long long y;
      tie(a, b) = edges[m];
      y = Ys[m];
      auto id = uf.find(a);
      auto score = group_sum[id];
      if (y > score) {
        ok = false;
        deleted_edge[m] = 1;
        ++ans;
      }
    }
    if (ok) break;
    for (int m = 0; m < (int)(M); ++m) {
      if (deleted_edge[m]) continue;
      int a, b;
      long long y;
      tie(a, b) = edges[m];
      y = Ys[m];
      uf.unite(a, b);
    }
    group_sum = vector<long long>(N);
    for (int n = 0; n < (int)(N); ++n) {
      auto id = uf.find(n);
      group_sum[id] += Xs[n];
    }
  }
  cout << ans << endl;
  return 0;
}
