#include <bits/stdc++.h>

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;
struct UnionFind {
  vector<pair<LL, LL>> memo;
  vector<LL> par;
  UnionFind(int n) {
    par = vector<LL>(n, -1);
  }
  int root(int x) {
    if (par[x] < 0) return x;
    return par[x] = root(par[x]);
  }
  int reversible_root(int x) {
    if (par[x] < 0) return x;
    return reversible_root(par[x]);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (par[x] < par[y]) swap(x, y);
      par[y] += par[x];
      par[x] = y;
    }
    return;
  }
  void reversible_unite(int x, int y) {
    x = reversible_root(x);
    y = reversible_root(y);
    if (x != y) {
      if (par[x] < par[y]) swap(x, y);
      memo.emplace_back(x, par[x]);
      memo.emplace_back(y, par[y]);
      par[y] += par[x];
      par[x] = y;
    }
    return;
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  int size(int x) {
    return -par[root(x)];
  }
  int reversible_size(int x) {
    return -par[reversible_root(x)];
  }
  void revert() {
    for (int i = memo.size() - 1; i >= 0; --i) {
      par[memo[i].first] = memo[i].second;
    }
    memo.clear();
  }
  void rollback(int i) {
    par[memo[i].first] = memo[i].second;
  }
};

class Solver2 {
 public:
  int n, m;
  UnionFind uf;
  vector<pair<pair<int, int>, pair<LL, int>>> edges;
  Solver2(LL n, LL m) : n(n),
                        m(m),
                        uf(n){};

  void solve() {
    for (int i = 0; i < n; ++i) {
      int tmp;
      cin >> tmp;
      uf.par[i] = -tmp;
    }
    for (int i = 0; i < m; ++i) {
      int a, b, y;
      cin >> a >> b >> y;
      --a;
      --b;
      edges.push_back({{a, b}, {y, -1}});
    }
    sort(edges.begin(), edges.end(), [&](auto xx, auto yy) { return xx.second.first < yy.second.first; });
    for (int i = 0; i < m; ++i) {
      int a = edges[i].first.first;
      int b = edges[i].first.second;
      if (uf.reversible_root(a) != uf.reversible_root(b)) {
        edges[i].second.second = uf.memo.size();
        uf.reversible_unite(a, b);
      }
    }
    int ans = 0;
    for (int i = m - 1; i >= 0; --i) {
      if (uf.reversible_size(edges[i].first.first) < edges[i].second.first) {
        ans++;
        if (edges[i].second.second != -1) {
          uf.rollback(edges[i].second.second);
          uf.rollback(edges[i].second.second + 1);
        }
      }
    }
    cout << ans << endl;
  }
};  // namespace Problem
}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0, m;
  std::cin >> n >> m;

  Problem::Solver2 sol(n, m);
  sol.solve();
  return 0;
}
