#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using graph = vector<set<int>>;
class union_find {
  vector<int> par;

 public:
  union_find(int n) : par(n, -1) {}
  int find(int a) { return par[a] < 0 ? a : par[a] = find(par[a]); }
  bool same(int a, int b) { return find(a) == find(b); }
  void unite(int a, int b) {
    a = find(a);
    b = find(b);
    if (a == b) return;
    if (par[a] < par[b]) {
      par[a] += par[b];
      par[b] = a;
    } else {
      par[b] += par[a];
      par[a] = b;
    }
  }
  int size(int a) { return -par[find(a)]; }
};
int main() {
  int N, M;
  cin >> N >> M;
  vector<ll> X(N);
  for (int i = 0; i < N; i++) {
    cin >> X[i];
  }
  vector<tuple<int, int, int>> tps;
  for (int i = 0; i < M; i++) {
    int A, B, Y;
    cin >> A >> B >> Y;
    --A, --B;
    tps.emplace_back(Y, A, B);
  }
  sort(tps.begin(), tps.end());
  vector<tuple<int, int, int>> tes, oth;
  int ok = 0, ng = 0;
  {
    union_find uf(N);
    vector<ll> ss = X, ma(N);
    for (auto tp : tps) {
      int A, B, Y;
      tie(Y, A, B) = tp;
      if (!uf.same(A, B)) {
        int a = uf.find(A), b = uf.find(B);
        ll ts = ss[a] + ss[b], tm = max(ma[a], ma[b]);
        if (ss[a] < ma[a]) --ng;
        if (ss[b] < ma[b]) --ng;
        uf.unite(A, B);
        a = uf.find(a);
        ss[a] = ts;
        ma[a] = max(tm, (ll)Y);
        if (ss[a] < ma[a]) ++ng;
        tes.emplace_back(Y, A, B);
        if (ng == 0) {
          ok = tes.size();
        }
      } else {
        oth.emplace_back(Y, A, B);
      }
    }
  }
  union_find uf(N);
  int res = tes.size() - ok;
  vector<ll> ss = X, ma(N);
  for (int t = 0; t < ok; t++) {
    int A, B, Y;
    tie(Y, A, B) = tes[t];
    int a = uf.find(A), b = uf.find(B);
    ll ts = ss[a] + ss[b], tm = max(ma[a], ma[b]);
    uf.unite(A, B);
    a = uf.find(a);
    ss[a] = ts;
    ma[a] = tm;
  }
  for (auto tp : oth) {
    int Y, A, B;
    tie(Y, A, B) = tp;
    int a = uf.find(A);
    int b = uf.find(B);
    if (a != b || ss[a] < Y) {
      ++res;
    }
  }
  cout << res << endl;
  return 0;
}
