#include <bits/stdc++.h>
using namespace std;
class UnionFind {
 public:
  vector<int> par, rank;
  UnionFind(int sz) : par(sz, -1), rank(sz, 0) {}
  int find(int x) {
    if (par[x] < 0)
      return x;
    else
      return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;
    if (rank[x] == rank[y]) rank[x]++;
  }
  inline bool same(int x, int y) { return find(x) == find(y); }
  inline int size(int x) { return -par[find(x)]; }
  inline bool isroot(int x) const { return par[x] < 0; }
};
int main() {
  int n, m;
  cin >> n >> m;
  vector<long> w(n);
  for (int i = (int)(0); i < (int)(n); i++) cin >> w[i];
  vector<pair<int, int>> e(m);
  vector<long> ew(m);
  for (int i = (int)(0); i < (int)(m); i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    e[i] = {a, b};
    cin >> ew[i];
  }
  int ans = m;
  long l = *min_element(begin(ew), end(ew)),
       r = *max_element(begin(ew), end(ew)) + 1;
  auto f = [&](long mid) {
    UnionFind uf(n);
    for (int i = (int)(0); i < (int)(m); i++)
      if (ew[i] < mid) uf.unite(e[i].first, e[i].second);
    vector<long> sz(n, 0);
    for (int i = (int)(0); i < (int)(n); i++) sz[uf.find(i)] += w[i];
    int el = 0;
    for (int i = (int)(0); i < (int)(m); i++) {
      if (ew[i] < mid) {
        if (ew[i] > sz[uf.find(e[i].first)]) return false;
      } else {
        if (!uf.same(e[i].first, e[i].second) ||
            ew[i] > sz[uf.find(e[i].first)])
          el++;
      }
    }
    ans = min(ans, el);
    return true;
  };
  while (r - l > 1) {
    long mid = (l + r) / 2;
    if (f(mid))
      l = mid;
    else
      r = mid;
  }
  f(l);
  f(r);
  cout << ans << endl;
  return 0;
}
