#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
int n, m;
int wei[200005];
pair<int, pair<int, int> > E[100005];
int hv[100005];
int tot;
int par[200005], val[200005];
vector<int> T[200005];
void init() {
  for (int i = 1; i <= (int)(n); i++) par[i] = i;
  tot = n;
}
int root(int x) { return par[x] == x ? x : par[x] = root(par[x]); }
int unite(int u, int v, int w) {
  u = root(u);
  v = root(v);
  if (u == v) return 0;
  tot++;
  T[tot].clear();
  par[tot] = tot;
  val[tot] = w;
  par[u] = par[v] = tot;
  T[tot].push_back(u);
  T[tot].push_back(v);
  return tot;
}
int ans;
long long sz[200005];
bool gg[200005];
void dfs0(int v) {
  sz[v] = wei[v];
  for (int i = 0; i < (int)(T[v].size()); i++) {
    dfs0(T[v][i]);
    sz[v] += sz[T[v][i]];
  }
}
void dfs1(int v) {
  if (sz[v] < val[v]) {
    gg[v] = true;
    ans++;
    for (int i = 0; i < (int)(T[v].size()); i++) dfs1(T[v][i]);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= (int)(n); i++) scanf("%d", &wei[i]);
  for (int i = 0; i < (int)(m); i++)
    scanf("%d%d%d", &E[i].second.first, &E[i].second.second, &E[i].first);
  sort(E, E + m);
  init();
  for (int i = 0; i < (int)(m); i++)
    hv[i] = unite(E[i].second.first, E[i].second.second, E[i].first);
  for (int i = 1; i <= (int)(tot); i++)
    if (par[i] == i) {
      dfs0(i);
      dfs1(i);
    }
  init();
  for (int i = 0; i < (int)(m); i++)
    if (hv[i] && !gg[hv[i]])
      unite(E[i].second.first, E[i].second.second, E[i].first);
  for (int i = 0; i < (int)(m); i++)
    if (!hv[i]) {
      int u = root(E[i].second.first), v = root(E[i].second.second);
      if (u != v || sz[u] < E[i].first) ans++;
    }
  printf("%d\n", ans);
  return 0;
}
