#include <bits/stdc++.h>
using std::bitset;
using std::cerr;
using std::cin;
using std::cout;
using std::deque;
using std::endl;
using std::fixed;
using std::ios_base;
using std::make_pair;
using std::make_tuple;
using std::map;
using std::nth_element;
using std::pair;
using std::queue;
using std::reverse;
using std::set;
using std::sort;
using std::stack;
using std::string;
using std::tuple;
using std::unordered_map;
using std::unordered_set;
using std::vector;
const int MAXN = 100000;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int64_t L_INF = 4e18;
struct Edge {
  int v, u, y;
  Edge(int v, int u, int y) : v(v), u(u), y(y) {}
  bool operator<(const Edge& other) const { return y < other.y; }
};
int n, m;
vector<Edge> edges;
int x[MAXN];
int comp[MAXN];
int64_t sum[MAXN];
int par[MAXN];
vector<int> g[MAXN];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);
  cout << fixed;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    par[i] = i;
    sum[i] = x[i];
    comp[i] = i;
    g[i].push_back(i);
  }
  for (int i = 0; i < m; i++) {
    int v, u, y;
    cin >> v >> u >> y;
    edges.emplace_back(--v, --u, y);
  }
  sort(edges.begin(), edges.end());
  for (auto& e : edges) {
    if (par[e.v] == par[e.u]) {
      continue;
    }
    vector<int>& a =
        g[par[e.v]].size() >= g[par[e.u]].size() ? g[par[e.v]] : g[par[e.u]];
    vector<int>& b =
        g[par[e.v]].size() >= g[par[e.u]].size() ? g[par[e.u]] : g[par[e.v]];
    int s = sum[a[0]] + sum[b[0]];
    sum[a[0]] = s;
    for (int v : b) {
      a.push_back(v);
      par[v] = a[0];
    }
    if (s < e.y) {
      continue;
    }
    for (int i = (int)a.size() - 1; i >= 0; i--) {
      if (comp[a[i]] == comp[a[0]]) {
        break;
      }
      comp[a[i]] = comp[a[0]];
    }
  }
  memset(sum, 0, sizeof sum);
  for (int i = 0; i < n; i++) {
    sum[comp[i]] += x[i];
  }
  int ans = 0;
  for (auto& e : edges) {
    if (comp[e.v] == comp[e.u] && e.y <= sum[comp[e.v]]) {
      ans++;
    }
  }
  cout << m - ans << '\n';
  return 0;
}
