#include <bits/stdc++.h>
using namespace std;
class UnionFind {
  vector<int> par;
  int n;

 public:
  UnionFind(int n) : par(n, -1) {}
  int find(int x) {
    if (par[x] < 0) return x;
    return par[x] = find(par[x]);
  }
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
};
int n, m, a, b;
long long y, x[100005], cost[100005];
bool candidate[100005], visited[100005];
vector<pair<long long, pair<int, int>>> edges;
vector<pair<int, long long>> G[100005];
pair<int, long long> dfs(int p, long long co) {
  visited[p] = true;
  long long ret = x[p];
  int count = 0;
  for (int i = 0; i < G[p].size(); i++) {
    if (G[p][i].second <= co) {
      if (visited[G[p][i].first]) {
        count++;
      } else {
        pair<int, long long> tmp = dfs(G[p][i].first, co);
        count += tmp.first + 1;
        ret += tmp.second;
      }
    }
  }
  return pair<int, long long>(count, ret);
}
int main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    cost[i] = x[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> y;
    a--;
    b--;
    edges.push_back(make_pair(y, make_pair(a, b)));
    G[a].push_back(make_pair(b, y));
    G[b].push_back(make_pair(a, y));
  }
  sort(edges.begin(), edges.end());
  UnionFind uf(n);
  for (int i = 0; i < m; i++) {
    a = edges[i].second.first;
    b = edges[i].second.second;
    y = edges[i].first;
    if (uf.same(a, b)) {
      if (cost[uf.find(a)] >= y) {
        candidate[i] = true;
      }
    } else {
      long long tmp = cost[uf.find(a)] + cost[uf.find(b)];
      uf.unite(a, b);
      cost[uf.find(a)] = tmp;
      if (tmp >= y) {
        candidate[i] = true;
      }
    }
  }
  int ans = m;
  for (int i = m - 1; i >= 0; i--) {
    if (!candidate[i]) continue;
    pair<int, long long> tmp = dfs(edges[i].second.first, edges[i].first);
    if (tmp.second >= edges[i].first) {
      ans -= tmp.first / 2;
    }
  }
  cout << ans << "\n";
  return 0;
}
