#include <bits/stdc++.h>
using namespace std;
int in() {
  int x;
  scanf("%d", &x);
  return x;
}
long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
void makegraph(int x, vector<vector<int> > &v) {
  for (long long i = 0; i < x - 1; i++) {
    int a = in(), b = in();
    v[a].push_back(b);
    v[b].push_back(a);
  }
}
template <typename A, size_t NNN, typename T>
void Fill(A (&array)[NNN], const T &val) {
  fill((T *)array, (T *)(array + NNN), val);
}
long long MOD = 1e9 + 7;
long long n, m, k;
struct edge {
  int from, to;
  long long cost;
};
struct UnionFind {
  vector<long long> par, sizes;
  UnionFind(int n) : par(n + 1), sizes(n + 1, 1) {
    for (long long i = 1; i <= n; ++i) par[i] = i;
  }
  int find(int x) { return (x == par[x] ? x : par[x] = find(par[x])); }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (sizes[x] < sizes[y]) {
      swap(x, y);
    }
    par[y] = x;
    sizes[x] += sizes[y];
  }
  bool same(int x, int y) { return (find(x) == find(y)); }
  long long size(int x) { return sizes[find(x)]; }
};
long long x[355050];
long long largest[355050];
vector<int> G[355050];
long long sz[355050];
int ans;
vector<edge> E;
void dfs(int x) {
  if (sz[x] >= E[x].cost) return;
  ans++;
  for (auto e : G[x]) {
    dfs(e);
  }
}
int main() {
  n = in();
  m = in();
  UnionFind u(n + 1 + m);
  for (long long i = 1; i <= n; ++i) {
    x[i] = lin();
    u.sizes[i] = x[i];
  }
  for (long long i = 0; i < m; i++) {
    int a = in(), b = in();
    long long c = lin();
    E.push_back(edge{a, b, c});
  }
  sort((E).begin(), (E).end(), [](edge x, edge y) { return x.cost < y.cost; });
  for (long long i = 0; i < n + 1; i++) largest[i] = -1;
  for (long long i = 0; i < m; i++) {
    int a = E[i].from, b = E[i].to;
    if (u.same(a, b)) {
      G[i].push_back(largest[u.find(a)]);
      sz[i] = u.size(a);
      largest[u.find(a)] = i;
    } else {
      int p1 = u.find(a), p2 = u.find(b);
      if (largest[p1] != -1) {
        G[i].push_back(largest[p1]);
      }
      if (largest[p2] != -1) G[i].push_back(largest[p2]);
      u.unite(a, b);
      largest[u.find(a)] = i;
      long long xx = u.size(a);
      sz[i] = xx;
    }
  }
  dfs(m - 1);
  cout << ans;
}
