#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
  vector<long long> v, w;
  UnionFind(int n) : v(n, -1), w(n, 0) {}
  void init() {
    for (int i = 0; i < (int)v.size(); i++) v[i] = -1;
  }
  int find(int x) { return v[x] < 0 ? x : find(v[x]); }
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (-v[x] < -v[y]) swap(x, y);
    w[x] += w[y];
    v[x] += v[y];
    v[y] = x;
    return true;
  }
  bool root(int x) { return v[x] < 0; }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -v[find(x)]; }
  long long weight(int x) { return w[find(x)]; }
};
struct edge {
  long long a, b, w;
};
long long n, m;
vector<edge> es;
long long x[200010];
bool dame[200010];
vector<long long> g[200010];
long long pre[200010], ew[200010], sw[200010], idx[200010];
long long V;
void dfs(int v) {
  if (v < n) return;
  if (sw[v] < ew[v]) {
    dame[idx[v]] = true;
    for (int nv : g[v]) dfs(nv);
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (long long i = (long long)(0); i < (long long)(n); i++) cin >> x[i];
  for (long long i = (long long)(0); i < (long long)(m); i++) {
    long long a, b, w;
    cin >> a >> b >> w;
    a--;
    b--;
    es.push_back((edge){a, b, w});
  }
  sort((es).begin(), (es).end(),
       [=](const edge& a, const edge& b) { return a.w < b.w; });
  UnionFind uf(n);
  for (long long i = (long long)(0); i < (long long)(n); i++) uf.w[i] = x[i];
  V = n;
  for (long long i = (long long)(0); i < (long long)(n); i++) pre[i] = i;
  for (long long i = (long long)(0); i < (long long)(m); i++) {
    if (!uf.same(es[i].a, es[i].b)) {
      ew[V] = es[i].w;
      sw[V] = uf.weight(es[i].a) + uf.weight(es[i].b);
      g[V].push_back(pre[uf.find(es[i].a)]);
      g[V].push_back(pre[uf.find(es[i].b)]);
      idx[V] = i;
      uf.unite(es[i].a, es[i].b);
      pre[uf.find(es[i].a)] = V;
      V++;
    }
  }
  dfs(V - 1);
  uf.init();
  for (long long i = (long long)(0); i < (long long)(n); i++) uf.w[i] = x[i];
  for (long long i = (long long)(0); i < (long long)(m); i++)
    if (!dame[i]) uf.unite(es[i].a, es[i].b);
  long long res = 0;
  for (long long i = (long long)(0); i < (long long)(m); i++) {
    if (uf.same(es[i].a, es[i].b) && uf.weight(es[i].a) >= es[i].w) continue;
    res++;
  }
  cout << res << endl;
  return 0;
}
