#include <bits/stdc++.h>
using namespace std;
const int N = 100050;
long long X[N];
int p[N], sz[N];
vector<int> E[N];
bool was[N];
int Find(int x) { return p[x] == x ? x : Find(p[x]); }
void Union(int x, int y) {
  x = Find(x);
  y = Find(y);
  if (sz[x] < sz[y]) swap(x, y);
  X[x] += X[y];
  p[y] = x;
  sz[x] += sz[y];
  E[x].push_back(y);
}
void Mark(int u) {
  if (was[u]) return;
  was[u] = 1;
  for (int v : E[u])
    if (!was[v]) Mark(v);
}
int main() {
  int n, m, u, v, w;
  scanf("%i %i", &n, &m);
  for (int i = 1; i <= n; i++) sz[i] = 1, p[i] = i;
  for (int i = 1; i <= n; i++) scanf("%lld", &X[i]);
  vector<pair<int, pair<int, int> > > edges;
  vector<pair<long long, int> > ws;
  for (int i = 1; i <= m; i++)
    scanf("%i %i %i", &u, &v, &w),
        edges.push_back(make_pair(w, make_pair(u, v)));
  sort(edges.begin(), edges.end());
  for (auto e : edges) {
    u = e.second.first;
    v = e.second.second;
    if (Find(u) != Find(v)) Union(u, v);
    ws.push_back(make_pair(X[Find(u)], Find(u)));
  }
  int ans = 0;
  for (int i = m - 1; i >= 0; i--) {
    u = edges[i].second.first;
    v = edges[i].second.second;
    w = edges[i].first;
    if (w > ws[i].first && !was[u]) {
      ans++;
    } else {
      Mark(ws[i].second);
    }
  }
  printf("%i\n", ans);
  return 0;
}
