#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<int> x(n);
  vector<array<int, 3> > edges(m);
  vector<vector<pair<int, int> > > g(n);
  for (int i = 0; i < n; ++i) {
    cin >> x[i];
  }
  for (int i = 0; i < m; ++i) {
    cin >> edges[i][1] >> edges[i][2] >> edges[i][0];
    --edges[i][1];
    --edges[i][2];
    g[edges[i][1]].emplace_back(edges[i][2], edges[i][0]);
    g[edges[i][2]].emplace_back(edges[i][1], edges[i][0]);
  }
  sort(edges.begin(), edges.end());
  vector<int> lab(n, -1);
  vector<long long> sum(n);
  vector<vector<int> > comp(n);
  vector<vector<pair<int, long long> > > sumRoot(n), getRoot(n);
  for (int i = 0; i < n; ++i) {
    sum[i] = x[i];
    comp[i].push_back(i);
    sumRoot[i].emplace_back(0, x[i]);
    getRoot[i].emplace_back(0, i);
  }
  function<int(int)> find = [&](int x) {
    if (lab[x] < 0) return x;
    return lab[x] = find(lab[x]);
  };
  function<bool(int, int, int)> join = [&](int x, int y, int w) {
    if ((x = find(x)) == (y = find(y))) return false;
    if (comp[x].size() < comp[y].size()) swap(x, y);
    sum[x] += sum[y];
    sumRoot[x].emplace_back(w, sum[x]);
    for (int &v : comp[y]) {
      comp[x].push_back(v);
      lab[v] = x;
      getRoot[v].emplace_back(w, x);
    }
    return true;
  };
  for (auto &p : edges) {
    join(p[1], p[2], p[0]);
  }
  function<int(int, int)> getWeightRoot = [&](int v, int w) {
    auto it = upper_bound(sumRoot[v].begin(), sumRoot[v].end(),
                          make_pair(w, (long long)1e18));
    it--;
    return it->second;
  };
  function<int(int, int)> getWeightVertice = [&](int v, int w) {
    auto it = upper_bound(getRoot[v].begin(), getRoot[v].end(),
                          make_pair(w, n + 1LL));
    it--;
    return getWeightRoot(it->second, w);
  };
  vector<bool> visited(n, false);
  map<pair<int, int>, bool> marked;
  function<void(int, int)> dfs = [&](int v, int w) {
    visited[v] = 1;
    for (auto e : g[v]) {
      if (e.second > w) continue;
      marked[make_pair(v, e.first)] = 1;
      if (visited[e.first]) continue;
      dfs(e.first, w);
    }
    return;
  };
  for (int i = edges.size() - 1; i >= 0; --i) {
    auto p = edges[i];
    if (marked[make_pair(p[1], p[2])]) {
      --m;
      continue;
    }
    if (getWeightVertice(p[1], p[0]) >= p[0]) {
      --m;
      dfs(p[1], p[0]);
    }
  }
  cout << m;
  return 0;
}
