#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long INF = 1LL << 60;
const long long mod = 1e9 + 7;
const long double eps = 1e-8;
const long double pi = acos(-1.0);
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
struct UnionFind {
  vector<int> par, w, sum;
  UnionFind(int n, vector<int> x) : par(n, -1), w(n, 0) { sum = x; }
  void init(int n) {
    par.assign(n, -1);
    w.assign(n, 0);
  }
  int root(int x) {
    if (par[x] < 0)
      return x;
    else
      return par[x] = root(par[x]);
  }
  bool issame(int x, int y) { return root(x) == root(y); }
  bool merge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) {
      ++w[x];
      return false;
    }
    if (par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    sum[x] += sum[y];
    par[y] = x;
    w[x] += w[y];
    ++w[x];
    return true;
  }
  int xsum(int x) { return sum[root(x)]; }
  int size(int x) { return -par[root(x)]; }
  int wei(int x) { return w[root(x)]; }
};
int n, m;
vector<int> x;
vector<vector<pair<int, int>>> g;
map<pair<int, int>, int> mp;
vector<bool> ok;
void dfs(int v, int val) {
  for (pair<int, int> e : g[v]) {
    if (e.second <= val && !ok[mp[{v, e.first}]]) {
      ok[mp[{v, e.first}]] = 1;
      dfs(e.first, val);
    }
  }
}
void solve() {
  cin >> n >> m;
  x.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  g.assign(n, vector<pair<int, int>>());
  vector<pair<int, pair<int, int>>> es(m);
  for (int i = 0; i < m; i++) {
    int a, b, y;
    cin >> a >> b >> y;
    --a, --b;
    g[a].push_back({b, y});
    g[b].push_back({a, y});
    es[i] = {y, {a, b}};
  }
  UnionFind uf(n, x);
  sort(es.begin(), es.end());
  for (int i = 0; i < m; i++) {
    mp[{es[i].second.first, es[i].second.second}] = i;
    mp[{es[i].second.second, es[i].second.first}] = i;
  }
  vector<bool> cand(m, 0);
  for (int i = 0; i < m; i++) {
    int val = es[i].first, a = es[i].second.first, b = es[i].second.second;
    uf.merge(a, b);
    if (uf.xsum(a) >= val) {
      cand[i] = 1;
    }
  }
  ok.assign(m, 0);
  for (int i = m - 1; i >= 0; i--) {
    if (cand[i]) {
      if (!ok[i]) {
        dfs(es[i].second.first, es[i].first);
      }
    }
  }
  int cnt = 0;
  for (int i = 0; i < m; i++) {
    if (!ok[i]) ++cnt;
  }
  cout << cnt << endl;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
