#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
long long lcm(long long x, long long y) { return x / gcd(x, y) * y; }
long long kai(long long x, long long y, long long m) {
  long long res = 1;
  for (long long i = x - y + 1; i <= x; i++) {
    res *= i;
    res %= m;
  }
  return res;
}
long long mod_pow(long long x, long long y, long long m) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) {
      res = res * x % m;
    }
    x = x * x % m;
    y >>= 1;
  }
  return res;
}
long long comb(long long x, long long y, long long m) {
  if (y > x) return 0;
  return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}
int par[100010], ran[100010];
long long cnt[100010];
void init(int n_) {
  for (int i = 1; i <= n_; i++) par[i] = i;
};
int find(int x) {
  if (par[x] == x)
    return x;
  else
    return par[x] = find(par[x]);
}
void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return;
  if (ran[x] < ran[y]) {
    par[x] = y;
    cnt[y] += cnt[x];
  } else {
    if (ran[x] == ran[y]) ran[x]++;
    par[y] = x;
    cnt[x] += cnt[y];
  }
}
int n, m, x[100010];
pair<int, pair<int, int>> y[100010];
vector<pair<int, int>> vec[100010];
long long a[100010];
bool bl[100010];
bool bl2[100010];
int ans;
void dfs(int v, int p, int k) {
  bl2[v] = true;
  for (int i = 0; i < (int)vec[v].size(); i++) {
    if (vec[v][i].first == p) continue;
    if (bl2[vec[v][i].first]) continue;
    if (k < vec[v][i].second) continue;
    bl[vec[v][i].second] = true;
    dfs(vec[v][i].first, v, k);
  }
  bl2[v] = false;
}
signed main() {
  std::random_device rnd;
  std::mt19937_64 mt(rnd());
  cin >> n >> m;
  init(n);
  for (int i = 1; i <= n; i++) cin >> x[i], cnt[i] = x[i];
  for (int i = 0; i < m; i++)
    cin >> y[i].second.first >> y[i].second.second >> y[i].first;
  sort(y, y + m);
  for (int i = 0; i < m; i++) {
    vec[y[i].second.first].push_back(make_pair(y[i].second.second, i));
    vec[y[i].second.second].push_back(make_pair(y[i].second.first, i));
    unite(y[i].second.first, y[i].second.second);
    a[i] = cnt[find(y[i].second.first)];
  }
  for (int i = m - 1; i >= 0; i--) {
    if (bl[i]) continue;
    if (a[i] < y[i].first)
      ans++;
    else
      dfs(y[i].second.first, 0, i);
  }
  cout << ans << endl;
}
