#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
  long long num;
  vector<long long> r, p, w;
  UnionFind() {}
  UnionFind(long long n) : num(n), r(n, 1), w(n), p(n, 0) {
    iota(p.begin(), p.end(), 0);
  }
  long long find(long long x) { return (x == p[x] ? x : p[x] = find(p[x])); }
  void init(vector<long long> v) { w = v; }
  bool same(long long x, long long y) { return find(x) == find(y); }
  void unite(long long x, long long y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (r[x] < r[y]) swap(x, y);
    r[x] += r[y];
    p[y] = x;
    w[x] += w[y];
    num--;
  }
  long long size(long long x) { return r[find(x)]; }
  long long weight(long long x) { return w[find(x)]; }
  long long count() const { return num; }
};
signed main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> w(N);
  for (long long i = 0; i < N; i++) cin >> w[i];
  vector<pair<pair<long long, long long>, pair<long long, long long> > > e(M);
  vector<pair<long long, long long> > edge[N];
  for (long long i = 0; i < M; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    e[i] = pair<pair<long long, long long>, pair<long long, long long> >(
        pair<long long, long long>(c, 0), pair<long long, long long>(a, b));
    edge[a].push_back(pair<long long, long long>(b, c));
    edge[b].push_back(pair<long long, long long>(a, c));
  }
  sort(e.begin(), e.end());
  UnionFind uf(N);
  uf.init(w);
  for (long long i = 0; i < N; i++) {
    long long W = e[i].first.first, U = e[i].second.first,
              V = e[i].second.second;
    uf.unite(U, V);
    if (W <= uf.weight(U)) e[i].first.second = 1;
  }
  sort(e.rbegin(), e.rend());
  set<pair<long long, long long> > s;
  for (long long i = 0; i < M; i++) {
    long long W = e[i].first.first, A = e[i].first.second,
              U = e[i].second.first, V = e[i].second.second;
    if (s.count(pair<long long, long long>(U, V))) continue;
    if (A == 0) continue;
    s.count(pair<long long, long long>(U, V));
    queue<long long> que;
    que.push(U);
    que.push(V);
    while (que.size()) {
      long long p = que.front();
      que.pop();
      for (auto q : edge[p]) {
        long long t = q.first, WE = q.second;
        if (s.count(pair<long long, long long>(min(p, t), max(p, t)))) continue;
        if (WE > W) continue;
        s.insert(pair<long long, long long>(min(p, t), max(p, t)));
        que.push(t);
      }
    }
  }
  cout << M - s.size() << endl;
}
