#include <bits/stdc++.h>
using namespace std;
int n, m;
long x[1 << 17];
int cnt = 0;
struct UF {
  int n;
  vector<int> parent, rank;
  vector<long> w, mw;
  UF(int n_ = 0) : n(n_), parent(n_), rank(n_, 0), w(n_), mw(n_, 0) {
    for (int i = 0; i < n_; i++) {
      parent[i] = i;
      w[i] = x[i];
    }
  }
  int find(int a) { return parent[a] != a ? parent[a] = find(parent[a]) : a; }
  bool same(int a, int b) { return find(a) == find(b); }
  bool unite(int a, int b) {
    a = find(a), b = find(b);
    if (a == b) return false;
    if (rank[a] < rank[b]) {
      parent[a] = b;
      cnt -= w[a] < mw[a];
      cnt -= w[b] < mw[b];
      w[b] += w[a];
      mw[b] = max(mw[b], mw[a]);
      cnt += w[b] < mw[b];
    } else {
      parent[b] = a;
      cnt -= w[a] < mw[a];
      cnt -= w[b] < mw[b];
      w[a] += w[b];
      mw[a] = max(mw[a], mw[b]);
      cnt += w[a] < mw[a];
      if (rank[a] == rank[b]) rank[a]++;
    }
    return true;
  }
};
vector<pair<int, long> > H[2 << 17];
vector<pair<long, pair<int, int> > > G;
int used[1 << 17];
void dfs(int u, int p, int c) {
  used[u] = c;
  for (int i = 0; i < H[u].size(); i++) {
    G.push_back(make_pair(H[u][i].second, minmax(u, H[u][i].first)));
    if (!used[H[u][i].first]) dfs(H[u][i].first, u, c);
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> x[i];
  UF uf(n);
  for (int i = 0; i < m; i++) {
    long y;
    int u, v;
    cin >> u >> v >> y;
    H[u - 1].push_back(make_pair(v - 1, y));
    H[v - 1].push_back(make_pair(u - 1, y));
  }
  int all = 0;
  for (int i = 0; i < n; i++) {
    if (used[i]) continue;
    G.clear();
    cnt = 0;
    dfs(i, -1, i + 1);
    int ans = G.size() / 2;
    sort(G.begin(), G.end());
    for (int i = 0; i < G.size(); i += 2) {
      int u = uf.find(G[i].second.first);
      cnt -= uf.w[u] < uf.mw[u];
      uf.mw[u] = max(uf.mw[u], G[i].first);
      cnt += uf.w[u] < uf.mw[u];
      uf.unite(G[i].second.first, G[i].second.second);
      if (cnt == 0) ans = (int)G.size() / 2 - i / 2 - 1;
    }
    all += ans;
  }
  cout << all << endl;
}
