#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long longinf = 1LL << 60;
const long long mod = 1e9 + 7;
long long a[101010];
struct ppUF {
  vector<int> par, ti;
  vector<long long> cost;
  vector<vector<pair<int, int>>> his;
  vector<vector<pair<long long, long long>>> costhis;
  ppUF(int n) : ti(n, inf + 1), par(n, -1), his(n), cost(n), costhis(n) {
    for (auto &vs : his) vs.emplace_back(-1, -1);
    for (int i = (int)0; i < (int)n; ++i) costhis[i].emplace_back(-1, a[i]);
    for (int i = (int)0; i < (int)n; ++i) cost[i] = a[i];
  }
  int find(int t, int x) {
    if (ti[x] > t) return x;
    return find(t, par[x]);
  }
  bool unite(int t, int x, int y) {
    x = find(t, x);
    y = find(t, y);
    if (x == y) return false;
    if (par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    cost[x] += cost[y];
    his[x].emplace_back(t, par[x]);
    costhis[x].emplace_back(t, cost[x]);
    par[y] = x;
    ti[y] = t;
    return true;
  }
  bool same(int t, int x, int y) { return find(t, x) == find(t, y); }
  int time(int x, int y) {
    if (!same(inf, x, y)) return -1;
    int ok = inf, ng = -1, mid = 0;
    while (ok - ng > 1) {
      mid = (ok + ng) / 2;
      if (same(mid, x, y))
        ok = mid;
      else
        ng = mid;
    }
    return ok;
  }
  int size(int t, int x) {
    x = find(t, x);
    return -prev(
                lower_bound(his[x].begin(), his[x].end(), pair<int, int>(t, 0)))
                ->second;
  }
  long long sum(int t, int x) {
    x = find(t, x);
    return prev(lower_bound(costhis[x].begin(), costhis[x].end(),
                            pair<long long, long long>{t, longinf}))
        ->second;
  }
};
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = (int)0; i < (int)n; ++i) cin >> a[i];
  int l[m], r[m], w[m];
  for (int i = (int)0; i < (int)m; ++i) {
    cin >> l[i] >> r[i] >> w[i];
    --l[i];
    --r[i];
  }
  vector<int> ord(m);
  iota(ord.begin(), ord.end(), 0);
  sort(ord.begin(), ord.end(), [&](int x, int y) { return w[x] < w[y]; });
  ppUF uf(n);
  for (int i = (int)0; i < (int)m; ++i) {
    uf.unite(i + 1, l[ord[i]], r[ord[i]]);
  }
  reverse(ord.begin(), ord.end());
  int ans = 0;
  int Time = m;
  for (int i = (int)0; i < (int)m; ++i) {
    int x = uf.find(Time, l[ord[i]]);
    if (uf.sum(Time, x) >= w[ord[i]]) continue;
    ++ans;
    Time = m - i - 1;
  }
  cout << ans << endl;
  return 0;
}
