#include <bits/stdc++.h>
using namespace std;
const int maxn = 100002;
struct edge {
  int u, v, y;
};
vector<edge> edges;
long long w[maxn], fa[maxn];
int n, m, ans;
bool vis[maxn], ban[maxn];
bool mycmp(edge &a, edge &b) { return a.y < b.y; }
vector<vector<int> > g;
int getfa(int u) {
  if (fa[u] < 0) return u;
  fa[u] = getfa(fa[u]);
  return fa[u];
}
void unify(int a, int b) {
  fa[b] += fa[a];
  fa[a] = b;
}
void keepEdges(int u, int lim) {
  for (int i = 0; i < g[u].size(); ++i) {
    int idx = g[u][i];
    if (!vis[idx] && !ban[idx] && edges[idx].y <= lim) {
      vis[idx] = true;
      keepEdges(edges[idx].v, lim);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    fa[i] = -x;
  }
  edges = vector<edge>(m);
  for (int i = 0; i < m; ++i) cin >> edges[i].u >> edges[i].v >> edges[i].y;
  sort(edges.begin(), edges.end(), mycmp);
  g = vector<vector<int> >(n + 1);
  for (int i = 0; i < m; ++i) {
    int u = edges[i].u, v = edges[i].v;
    g[u].push_back(i);
    g[v].push_back(i);
    int f1 = getfa(u);
    int f2 = getfa(v);
    if (f1 == f2)
      w[i] = -fa[f1];
    else {
      w[i] = -fa[f1] - fa[f2];
      unify(f1, f2);
    }
  }
  for (int i = m - 1; i >= 0; --i)
    if (!vis[i]) {
      if (edges[i].y > w[i]) {
        ban[i] = vis[i] = true;
        ++ans;
      } else
        keepEdges(edges[i].u, edges[i].y);
    }
  cout << ans << endl;
  return 0;
}
