#include <bits/stdc++.h>
using namespace std;
class disjoint_set {
  public:
    vector<int> rank, p, cnt;
    vector<long long> wt;
    disjoint_set (int size) {
      rank.resize(size, 0);
      p.resize(size, 0);
      for (int i = 0; i < size; i++) {
        p[i] = i;
        rank[i] = 0;
      }
      wt.resize(size, 0);
      cnt.resize(size, 0);
    }
    void initWt (int x, int w) {
      wt[x] = w;
    }
    long long getWt (int x) {
      return wt[find(x)];
    }
    void addCnt (int x) {
      cnt[find(x)]++;
    }
    void clrCnt (int x) {
      cnt[find(x)] = 0;
    }
    int getCnt (int x) {
      return cnt[find(x)];
    }
    bool is_equiv (int x, int y) {
      return find(x) == find(y);
    }
    void unite (int x, int y) {
      x = find(x);
      y = find(y);
      if (x == y) {
        return;
      }
      if (rank[x] > rank[y]) {
        p[y] = x;
        wt[x] += wt[y];
        cnt[x] += cnt[y];
      } else {
        p[x] = y;
        wt[y] += wt[x];
        cnt[y] += cnt[x];
        if (rank[x] == rank[y]) {
          rank[y]++;
        }
      }
    }
    int find (int x) {
      if (x != p[x]) {
        p[x] = find(p[x]);
      }
      return p[x];
    }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  disjoint_set djs(n);
  for (int i = 0; i < n; i++) {
    int w;
    cin >> w;
    djs.initWt(i, w);
  }
  vector<pair<int, pair<int, int>>> edg(m);
  for (int i = 0; i < m; i++) {
    int a, b, w;
    cin >> a >> b >> w;
    a--;
    b--;
    edg[i] = {w, {a, b}};
  }
  sort(edg.begin(), edg.end());
  int usd = 0;
  for (auto e : edg) {
    int w = e.first;
    int a = e.second.first;
    int b = e.second.second;
    int r = djs.find(a);
    djs.unite(r, b);
    djs.addCnt(r);
    if (w <= djs.getWt(r)) {
      usd += djs.getCnt(r);
      djs.clrCnt(r);
    }
  }
  int ans = m - usd;
  cout << ans << '\n';
  return 0;
}