#include <bits/stdc++.h>
using namespace std;
class DSU {
 private:
  vector<long long> parents;
  vector<long long> sizes;
  vector<long long> weights;

 public:
  DSU(long long n, vector<long long> w) {
    parents.resize(n + 1);
    for (long long i = 1; i <= n; ++i) parents[i] = i;
    sizes.resize(n + 1);
    for (long long i = 1; i <= n; ++i) sizes[i] = 1;
    weights = w;
  }
  long long root(long long i) {
    while (parents[i] != i) {
      parents[i] = parents[parents[i]];
      i = parents[i];
    }
    return i;
  }
  long long getWeight(long long i) {
    long long r = root(i);
    return weights[r];
  }
  bool find(long long a, long long b) { return root(a) == root(b); }
  void join(long long a, long long b) {
    long long root_a = root(a);
    long long root_b = root(b);
    if (root_a == root_b) return;
    if (sizes[root_a] < sizes[root_b]) {
      parents[root_a] = parents[root_b];
      sizes[root_b] += sizes[root_a];
      weights[root_b] += weights[root_a];
    } else {
      parents[root_b] = parents[root_a];
      sizes[root_a] += sizes[root_b];
      weights[root_a] += weights[root_b];
    }
  }
};
struct edge {
  long long a;
  long long b;
  long long weight;
  bool operator<(const edge& other) const { return weight < other.weight; }
};
edge make_edge(long long aa, long long bb, long long w) {
  edge e;
  e.a = aa;
  e.b = bb;
  e.weight = w;
  return e;
}
int32_t main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> x(n + 1);
  for (long long i = 1; i <= n; ++i) cin >> x[i];
  vector<vector<edge>> graph(n + 1, vector<edge>());
  DSU dsu(n, x);
  vector<edge> edges(m);
  for (long long i = 0; i < m; ++i)
    cin >> edges[i].a >> edges[i].b >> edges[i].weight;
  sort(edges.begin(), edges.end());
  vector<long long> leftBehind(n + 1, 0);
  long long ret = 0;
  for (long long i = 0; i < m; ++i) {
    edge& cur = edges[i];
    if (dsu.find(cur.a, cur.b)) {
      if (cur.weight > dsu.getWeight(cur.a)) {
        ret++;
      }
    } else {
      long long ra = dsu.root(cur.a), rb = dsu.root(cur.b);
      dsu.join(cur.a, cur.b);
      long long root = dsu.root(cur.a);
      long long nw = dsu.getWeight(cur.a);
      leftBehind[root] = leftBehind[ra] + leftBehind[rb];
      if (cur.weight > nw) {
        leftBehind[root]++;
        ret++;
      } else {
        ret -= leftBehind[root];
        leftBehind[root] = 0;
      }
    }
  }
  cout << ret << endl;
  return 0;
}
