#include <bits/stdc++.h>
using namespace std;
class UnionFind {
 private:
  vector<long long> p, s, w;
  vector<vector<long long>> h;

 public:
  UnionFind(const vector<long long>& v)
      : p(v.size(), -1), s(v.size(), 1), w(v.begin(), v.end()) {}
  void wrap() { h.push_back({}); }
  void unwrap() {
    long long k = h.back().size();
    for (long long i = 0; i < (k); i++) {
      s[p[h.back()[k - 1 - i]]] -= s[h.back()[k - 1 - i]];
      w[p[h.back()[k - 1 - i]]] -= w[h.back()[k - 1 - i]];
      p[h.back()[k - 1 - i]] = -1;
    }
    h.pop_back();
  }
  long long find(long long a) {
    if (p[a] < 0) {
      return a;
    }
    return find(p[a]);
  }
  void unite(long long a, long long b) {
    a = find(a);
    b = find(b);
    if (a != b) {
      if (s[a] >= s[b]) {
        h.back().push_back(b);
        s[a] += s[b];
        w[a] += w[b];
        p[b] = a;
      } else {
        h.back().push_back(a);
        s[b] += s[a];
        w[b] += w[a];
        p[a] = b;
      }
    }
  }
  long long get(long long a) { return w[find(a)]; }
};
vector<long long> v;
vector<pair<long long, pair<long long, long long>>> ed;
vector<long long> dfs(long long b, long long e, UnionFind& uf) {
  if (b == e - 1) {
    uf.wrap();
    uf.unite(ed[b].second.first, ed[b].second.second);
    if (uf.get(ed[b].second.first) >= ed[b].first) {
      uf.unwrap();
      return {b};
    } else {
      uf.unwrap();
      return {};
    }
  } else {
    long long m = (b + e) / 2;
    uf.wrap();
    for (long long i = b; i < m; i++) {
      uf.unite(ed[i].second.first, ed[i].second.second);
    }
    auto r1 = dfs(m, e, uf);
    uf.unwrap();
    uf.wrap();
    for (auto i : r1) {
      uf.unite(ed[i].second.first, ed[i].second.second);
    }
    auto r2 = dfs(b, m, uf);
    uf.unwrap();
    r2.insert(r2.end(), r1.begin(), r1.end());
    return r2;
  }
}
signed main() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < (n); i++) {
    long long w;
    cin >> w;
    v.push_back(w);
  }
  for (long long i = 0; i < (m); i++) {
    long long a, b, y;
    cin >> a >> b >> y;
    ed.push_back(make_pair(y, make_pair(a - 1, b - 1)));
  }
  sort(ed.begin(), ed.end());
  UnionFind uf(v);
  cout << m - dfs(0, m, uf).size() << endl;
}
