#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
long long x[100005];
int n, m, par[100005], hei[100005];
struct edge {
  int u, v, w, y;
  bool operator<(const edge &e) const { return w < e.w; }
} el[100005];
void ini() {
  for (int i = 1; i <= n; i++) {
    par[i] = i;
    hei[i] = 1;
  }
}
int fin(int u) {
  if (par[u] == u) return u;
  return par[u] = fin(par[u]);
}
int uni(int u, int v) {
  u = fin(u), v = fin(v);
  if (u == v) {
    return x[u];
  } else {
    if (hei[u] < hei[v]) {
      par[u] = v;
      x[v] += x[u];
      x[u] = 0;
      return x[v];
    } else {
      par[v] = u;
      x[u] += x[v];
      x[v] = 0;
      if (hei[u] == hei[v]) hei[u]++;
      return x[u];
    }
  }
}
vector<pair<int, int> > adj[100005];
bool vis[100005];
void dfs(int u, int lim) {
  vis[u] = true;
  for (int i = 0; i < (int)adj[u].size(); i++) {
    pair<int, int> e = adj[u][i];
    if (vis[e.first] || e.second > lim) continue;
    dfs(e.first, lim);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%lld", &x[i]);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &el[i].u, &el[i].v, &el[i].w);
    adj[el[i].u].push_back(make_pair(el[i].v, el[i].w));
    adj[el[i].v].push_back(make_pair(el[i].u, el[i].w));
  }
  sort(el + 1, el + m + 1);
  ini();
  for (int i = 1; i <= m; i++) el[i].y = uni(el[i].u, el[i].v);
  int ans = 0;
  for (int i = m; i >= 1; i--) {
    if (vis[el[i].u]) continue;
    if (el[i].y >= el[i].w) {
      dfs(el[i].u, el[i].w);
      if (!vis[el[i].v]) dfs(el[i].v, el[i].w);
    } else
      ans++;
  }
  printf("%d\n", ans);
  return 0;
}
