#include <bits/stdc++.h>
using namespace std;
string char_to_str(char c) {
  string tem(1, c);
  return tem;
}
long long a[100001];
long long dsu[100001];
long long size[100001];
long long med[100001];
long long suw[100001];
long long e[100001];
long long vis[100001];
vector<pair<long long, pair<long long, long long>>> gr[100001];
long long root(long long i) {
  if (dsu[i] == i) return i;
  dsu[i] = root(dsu[i]);
  return dsu[i];
}
void dfs(long long i, long long w) {
  if (vis[i] == 1) return;
  vis[i] = 1;
  for (auto r : gr[i]) {
    if (r.second.first <= w) {
      e[r.second.second] = 1;
      dfs(r.first, w);
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long n, m;
  cin >> n >> m;
  for (long long i = 1; i <= n; ++i) cin >> a[i];
  pair<long long, pair<long long, long long>> ed[m];
  for (long long i = 0; i < m; ++i) {
    long long x, y, w;
    cin >> x >> y >> w;
    ed[i].second.first = x;
    ed[i].second.second = y;
    ed[i].first = w;
  }
  sort(ed, ed + m);
  long long valid[m + 1];
  for (long long i = 1; i <= n; ++i) {
    dsu[i] = i;
    size[i] = 1;
    valid[i] = 1;
    med[i] = 0;
    suw[i] = a[i];
  }
  long long inv = 0;
  for (long long i = 0; i < m; ++i) {
    long long x, y, w;
    x = ed[i].second.first;
    y = ed[i].second.second;
    w = ed[i].first;
    gr[x].push_back({y, {w, i}});
    gr[y].push_back({x, {w, i}});
    long long rx = root(x);
    long long ry = root(y);
    if (rx == ry) {
      med[rx] = max(med[rx], w);
      if (med[rx] <= suw[rx]) {
        valid[i] = 1;
      } else
        valid[i] = 0;
    } else {
      if (size[rx] < size[ry]) swap(rx, ry);
      dsu[ry] = rx;
      suw[rx] += suw[ry];
      med[rx] = max(med[rx], med[ry]);
      size[rx] += size[ry];
      med[rx] = max(med[rx], w);
      if (med[rx] <= suw[rx]) {
        valid[i] = 1;
      } else
        valid[i] = 0;
    }
  }
  for (long long i = m - 1; i >= 0; --i) {
    if (valid[i] == 0) continue;
    long long x, y, w;
    x = ed[i].second.first;
    y = ed[i].second.second;
    w = ed[i].first;
    if (vis[x] == 1 || vis[y] == 1) continue;
    dfs(x, w);
  }
  long long ans = 0;
  for (long long i = 0; i < m; ++i) ans += !e[i];
  cout << ans;
}
