#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
  return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
  std::copy(std::begin(c), std::end(c),
            std::ostream_iterator<typename C::value_type>(os, " "));
  os << std::endl;
}
struct UnionFind {
  vector<int> rank, parent, size;
  vector<int> cnt;
  UnionFind(int n)
      : rank(n + 1, 0), parent(n + 1), size(n + 1, 1), cnt(n + 1, 0) {
    iota(parent.begin(), parent.end(), 0);
  }
  int root(int x) {
    if (x != parent[x]) {
      parent[x] = root(parent[x]);
    }
    return parent[x];
  }
  bool isSame(int x, int y) { return root(x) == root(y); }
  bool unite(int x, int y) { return link(root(x), root(y)); }
  bool link(int x, int y) {
    if (x == y) return false;
    if (rank[x] > rank[y]) {
      parent[y] = x;
      size[x] += size[y];
      cnt[x] += cnt[y];
    } else {
      parent[x] = y;
      size[y] += size[x];
      cnt[y] += cnt[x];
      if (rank[x] == rank[y]) {
        rank[y]++;
      }
    }
    return true;
  }
  int getSize(int x) { return size[root(x)]; }
  void add(int x, int a) { cnt[root(x)] += a; }
  int getCnt(int x) { return cnt[root(x)]; }
  void clr(int x) { cnt[root(x)] = 0; }
};
int main() {
  int n, m;
  cin >> n >> m;
  vl x(n);
  UnionFind uf(n);
  for (int i = 0; i < n; ++i) {
    cin >> x[i];
    uf.size[i] = x[i];
  }
  vector<pair<int, pii>> edges;
  for (int i = 0; i < m; ++i) {
    int a, b, y;
    cin >> a >> b >> y;
    a--, b--;
    edges.push_back({y, {a, b}});
  }
  sort(edges.begin(), edges.end());
  int ret = 0;
  for (int i = 0; i < m; ++i) {
    int cost = edges[i].first;
    pii edge = edges[i].second;
    uf.unite(edge.first, edge.second);
    uf.add(edge.first, 1);
    if (cost <= uf.getSize(edge.first)) {
      ret += uf.getCnt(edge.first);
      uf.clr(edge.first);
    }
  }
  cout << m - ret << "\n";
  return 0;
}
