#include <bits/stdc++.h>
namespace loquat {
class disjoint_set {
 public:
  using value_type = size_t;

 private:
  std::vector<value_type> m_parents;
  std::vector<value_type> m_ranks;

 public:
  explicit disjoint_set(size_t n) : m_parents(n), m_ranks(n) {
    for (size_t i = 0; i < n; ++i) {
      m_parents[i] = i;
    }
  }
  value_type find(size_t x) {
    if (m_parents[x] == x) {
      return x;
    }
    m_parents[x] = find(m_parents[x]);
    return m_parents[x];
  }
  value_type unite(size_t x, size_t y) {
    x = find(x);
    y = find(y);
    if (x == y) {
      return x;
    }
    if (m_ranks[x] < m_ranks[y]) {
      m_parents[x] = y;
      return y;
    } else if (m_ranks[x] > m_ranks[y]) {
      m_parents[y] = x;
      return x;
    } else {
      m_parents[y] = x;
      ++m_ranks[x];
      return x;
    }
  }
  bool same(size_t x, size_t y) { return find(x) == find(y); }
};
}  // namespace loquat
using namespace std;
using ll = long long;
using tlii = tuple<ll, int, int>;
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<ll> x(n);
  for (int i = 0; i < n; ++i) {
    cin >> x[i];
  }
  vector<tlii> edges;
  for (int i = 0; i < m; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    --a;
    --b;
    edges.emplace_back(c, a, b);
  }
  sort(edges.begin(), edges.end());
  loquat::disjoint_set ds(n);
  vector<int> prev_a(m, -1), prev_b(m, -1), last(n, -1);
  vector<ll> sizes(m, 0);
  for (int i = 0; i < m; ++i) {
    const ll c = get<0>(edges[i]);
    const int a = get<1>(edges[i]);
    const int b = get<2>(edges[i]);
    if (ds.same(a, b)) {
      const int t = last[ds.find(a)];
      prev_a[i] = prev_b[i] = t;
    } else {
      prev_a[i] = last[ds.find(a)];
      prev_b[i] = last[ds.find(b)];
      const ll new_c = x[ds.find(a)] + x[ds.find(b)];
      const int k = ds.unite(a, b);
      x[k] = new_c;
    }
    last[ds.find(a)] = i;
    sizes[i] = x[ds.find(a)];
  }
  int answer = 0;
  vector<int> marker(m, 0);
  marker[m - 1] = 1;
  for (int i = m - 1; i >= 0; --i) {
    if (!marker[i]) {
      continue;
    }
    const ll c = get<0>(edges[i]);
    const int a = get<1>(edges[i]);
    const int b = get<2>(edges[i]);
    if (c > sizes[i]) {
      ++answer;
      if (prev_a[i] >= 0) {
        marker[prev_a[i]] = 1;
      }
      if (prev_b[i] >= 0) {
        marker[prev_b[i]] = 1;
      }
    }
  }
  cout << answer << endl;
  return 0;
}
