#include <bits/stdc++.h>
using namespace std;
struct D {
  long long a, b, c, id;
};
bool operator<(const D &lhs, const D &rhs) {
  if (lhs.c < rhs.c) {
    return true;
  } else if (lhs.c == rhs.c) {
    if (lhs.id < rhs.id) {
      return true;
    }
  }
  return false;
}
long long n, m, ans = 0, use[100010] = {}, y[100010];
vector<int> x(100010), v[100010], id[100010];
vector<D> cand;
D edge[100010];
struct UnionFind {
  int n;
  vector<int> sum, r, p;
  UnionFind() {}
  UnionFind(int sz) : n(sz), r(sz, 1), p(sz, 0) {
    iota(p.begin(), p.end(), 0);
    sum = x;
  }
  int find(int x) { return (x == p[x] ? x : p[x] = find(p[x])); }
  bool same(int x, int y) { return find(x) == find(y); }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (r[x] < r[y]) swap(x, y);
    r[x] += r[y];
    sum[x] += sum[y];
    p[y] = x;
  }
  int energy(int x) { return sum[find(x)]; }
};
int main(void) {
  cin >> n >> m;
  for (int i = ((int)(1)); i <= ((int)(n)); i++) cin >> x[i];
  for (int i = ((int)(1)); i <= ((int)(m)); i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    edge[i] = {a, b, c, i};
    v[a].push_back(b);
    v[b].push_back(a);
    id[a].push_back(i);
    id[b].push_back(i);
    y[i] = c;
  }
  sort(edge + 1, edge + 1 + m);
  UnionFind f(n + 1);
  for (int i = ((int)(1)); i <= ((int)(m)); i++) {
    f.unite(edge[i].a, edge[i].b);
    long long sum = f.energy(edge[i].a);
    if (sum >= edge[i].c) cand.push_back(edge[i]);
  }
  for (int i = ((int)(cand.size()) - 1); i >= 0; i--) {
    if (use[cand[i].id] == 0) {
      queue<long long> Q;
      Q.push(cand[i].a);
      Q.push(cand[i].b);
      use[cand[i].id] = 1;
      while (!Q.empty()) {
        long long p = Q.front();
        Q.pop();
        for (int j = 0; j < ((int)(v[p].size())); j++) {
          if (use[id[p][j]] == 0 && y[id[p][j]] <= y[cand[i].id]) {
            use[id[p][j]] = 1;
            Q.push(v[p][j]);
          }
        }
      }
    }
  }
  for (int i = ((int)(1)); i <= ((int)(m)); i++)
    if (use[i] == 0) ans++;
  cout << ans << endl;
  return 0;
}
