#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 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() {}
};
template <typename T>
struct UFkai {
  vector<int> par, siz;
  vector<T> a;
  using F = function<T(T, T)>;
  const F f;
  UFkai(int n, F f) : f(f) {
    par.resize(n);
    siz.assign(n, 1);
    iota(par.begin(), par.end(), 0);
    a.resize(n, 0);
  }
  void set(int i, T x) { a[i] = x; }
  int root(int x) { return (par[x] == x ? x : (par[x] = root(par[x]))); }
  bool unite(int x, int y) {
    x = root(x), y = root(y);
    if (x == y) return false;
    if (siz[x] < siz[y]) swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    a[x] = f(a[x], a[y]);
    return true;
  }
  T get(int x) { return a[root(x)]; }
  int size(int x) { return siz[root(x)]; }
  bool sameRoot(int x, int y) { return root(x) == root(y); }
};
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;
  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));
  }
  sort(es.begin(), es.end(), [](edge u, edge v) { return u.cost < v.cost; });
  function<ll(ll, ll)> f = [](ll u, ll v) { return u + v; };
  UFkai<ll> us(n, f);
  for (int i = 0; i < (n); i++) us.set(i, a[i]);
  vector<bool> check(m, false);
  for (auto e : es) {
    us.unite(e.from, e.to);
    if (us.get(e.from) >= e.cost) check[e.id] = true;
  }
  reverse(es.begin(), es.end());
  function<bool(bool, bool)> f2 = [](bool u, bool v) { return u | v; };
  UFkai<bool> uc(n, f2);
  int cnt = 0;
  for (auto e : es) {
    uc.unite(e.from, e.to);
    if (check[e.id]) uc.a[uc.root(e.from)] = true;
    if (!uc.get(e.from)) cnt++;
  }
  cout << cnt << endl;
  return 0;
}
