#include <bits/stdc++.h>
using namespace std;

struct Unionfind {
  // tree number
  vector<int> par;
  // constructor
  Unionfind(int n = 1) : par(n, -1) {}
  // search root
  int root(int x) {
    if (par[x] < 0) return x;
    return par[x] = root(par[x]);
  }
  // is same?
  bool issame(int x, int y) { return root(x) == root(y); }

  // add
  // already added, return 0
  int uni(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return x;
    if (par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return x;
  }
  int size(int x) { return -par[root(x)]; }
};

struct edge {
  int x, y;
  long long c;
  bool operator<(const edge& r) {
    if (c != r.c) return c < r.c;
    if (x != r.x) return x < r.x;
    return y < r.y;
  }
};

long long n, m;
vector<edge> edges;
vector<long long> a, sum;
vector<vector<long long>> v;
Unionfind tmp, uf;

long long solve();

int main() {
  cin >> n >> m;
  a.resize(n);
  for (auto& p : a) cin >> p;
  edges.resize(m);
  for (int i = 0; i < m; ++i) {
    cin >> edges[i].x >> edges[i].y >> edges[i].c;
    --edges[i].x, --edges[i].y;
  }
  sort(edges.begin(), edges.end());
  cout << solve() << endl;
  return 0;
}

long long solve() {
  uf = Unionfind(n);
  tmp = Unionfind(n);
  v.resize(n);
  sum = a;
  for (int i = 0; i < m; ++i)
    if (!tmp.issame(edges[i].x, edges[i].y)) {
      int x = tmp.root(edges[i].x), y = tmp.root(edges[i].y), r;
      if (v[y].size() > v[x].size()) swap(x, y);
      while (v[y].size()) {
        v[x].push_back(v[y].back());
        v[y].pop_back();
      }
      v[x].push_back(i);
      r = tmp.uni(x, y);
      sum[r] = sum[x] + sum[y];
      if (sum[r] >= edges[i].c)
        while (v[x].size()) {
          int id = v[x].back();
          uf.uni(edges[id].x, edges[id].y);
          v[x].pop_back();
        }
    }
  sum.assign(n, 0);
  for (int i = 0; i < n; ++i) sum[uf.root(i)] += a[i];
  long long res = m;
  for (int i = 0; i < m; ++i)
    if (uf.issame(edges[i].x, edges[i].y) &&
        sum[uf.root(edges[i].x)] >= edges[i].c)
      --res;
  return res;
}
