#include <bits/stdc++.h>
using namespace std;
class disjoint_set {
 public:
  vector<int> rank, p;
  vector<long long> wt;
  disjoint_set(){};
  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);
  }
  void setwt(int x, int w) { wt[x] = w; }
  bool is_equiv(int x, int y) { return find_set(x) == find_set(y); }
  void unite(int x, int y) { link(find_set(x), find_set(y)); }
  void link(int x, int y) {
    if (rank[x] > rank[y]) {
      p[y] = x;
      wt[x] += wt[y];
      wt[y] = 0;
    } else {
      p[x] = y;
      wt[y] += wt[x];
      wt[x] = 0;
      if (rank[x] == rank[y]) {
        rank[y]++;
      }
    }
  }
  int find_set(int x) {
    if (x != p[x]) {
      p[x] = find_set(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 tmp;
    cin >> tmp;
    djs.setwt(i, tmp);
  }
  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());
  vector<vector<int>> adj(n);
  for (int i = 0; i < m; i++) {
    auto e = edg[i];
    int a = e.second.first;
    int b = e.second.second;
    adj[a].push_back(i);
    adj[b].push_back(i);
  }
  vector<int> cdd(m, 0);
  for (int i = 0; i < m; i++) {
    auto e = edg[i];
    int y = e.first;
    int a = e.second.first;
    int b = e.second.second;
    if (!djs.is_equiv(a, b)) {
      djs.unite(a, b);
    }
    if (y < djs.wt[djs.p[a]]) {
      cdd[i] = true;
    }
  }
  vector<int> ckd(m, 0);
  stack<int> stk;
  for (int i = m - 1; i >= 0; i--) {
    if (cdd[i]) {
      int supw = edg[i].first;
      stk.push(i);
      ckd[i] = true;
      while (!stk.empty()) {
        int crr = stk.top();
        stk.pop();
        int crrs = edg[crr].second.first;
        int crrt = edg[crr].second.second;
        for (auto nxt : adj[crrs]) {
          int nxtw = edg[nxt].first;
          if (!ckd[nxt] && nxtw <= supw) {
            stk.push(nxt);
            ckd[nxt] = true;
          }
        }
        for (auto nxt : adj[crrt]) {
          int nxtw = edg[nxt].first;
          if (!ckd[nxt] && nxtw <= supw) {
            stk.push(nxt);
            ckd[nxt] = true;
          }
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < m; i++) {
    if (!ckd[i]) {
      ans++;
    }
  }
  cout << ans << '\n';
  return 0;
}
