#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1000000000;
const ll LINF = 1001002003004005006ll;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
struct IOSetup {
  IOSetup() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(12);
  }
} iosetup;
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << p.first << " " << p.second;
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < (int)v.size(); i++)
    os << v[i] << (i + 1 == v.size() ? "" : " ");
  return os;
}
struct UnionFind {
  vector<int> par;
  vector<int> siz;
  vector<ll> a;
  int c;
  void init(int n) {
    c = n;
    for (int i = 0; i < n; i++) {
      par.push_back(i);
      siz.push_back(1);
    }
    a.assign(n, 0);
  }
  UnionFind(int n) { init(n); }
  int root(int x) { return (par[x] == x ? x : (par[x] = root(par[x]))); }
  bool sameParent(int x, int y) { return (root(x) == root(y)); }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    if (siz[x] < siz[y]) swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    c--;
    a[x] += a[y];
  }
  int size(int x) { return siz[root(x)]; }
};
struct edge {
  int from, to, id;
  ll cost;
  edge(int from, int to, ll cost, int id = -1)
      : from(from), to(to), cost(cost), id(id) {}
  edge() {}
};
signed main() {
  int n, m;
  cin >> n >> m;
  vector<ll> a(n);
  for (int i = 0; i < (n); i++) cin >> a[i];
  vector<edge> es;
  vector<vector<edge>> g(n);
  for (int i = 0; i < (m); i++) {
    int u, v;
    ll c;
    cin >> u >> v >> c;
    u--, v--;
    es.push_back(edge(u, v, c, i));
    g[u].push_back(edge(u, v, c, i));
    g[v].push_back(edge(v, u, c, i));
  }
  sort(es.begin(), es.end(),
       [](edge lhs, edge rhs) { return lhs.cost < rhs.cost; });
  UnionFind uf(n);
  for (int i = 0; i < (n); i++) uf.a[i] = a[i];
  vector<bool> check(m, false);
  for (auto e : es) {
    uf.unite(e.from, e.to);
    if (uf.a[uf.root(e.from)] >= e.cost) {
      check[e.id] = true;
    }
  }
  function<void(int, ll)> dfs = [&](int now, ll lim) {
    for (auto e : g[now]) {
      if (check[e.id]) continue;
      if (e.cost <= lim) {
        check[e.id] = true;
        dfs(e.to, lim);
      }
    }
  };
  reverse(es.begin(), es.end());
  for (auto e : es) {
    if (!check[e.id]) continue;
    dfs(e.from, e.cost);
    dfs(e.to, e.cost);
  }
  int ans = 0;
  for (int i = 0; i < (m); i++)
    if (!check[i]) ans++;
  cout << ans << endl;
  return 0;
}
