#include <bits/stdc++.h>
using namespace std;
struct UF {
  vector<int> d;
  vector<long long> sm;
  vector<pair<int, int>> history;
  vector<pair<int, long long>> smHis;
  UF() {}
  UF(int mx, vector<long long> S) : d(mx, -1), sm(S) {}
  int root(int x) {
    if (d[x] < 0) return x;
    return root(d[x]);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    if (d[x] > d[y]) swap(x, y);
    if (d[x] == d[y]) {
      history.emplace_back(x, d[x]);
      d[x]--;
    }
    smHis.emplace_back(x, sm[x]);
    smHis.emplace_back(y, sm[y]);
    sm[x] += sm[y];
    history.emplace_back(y, d[y]);
    d[y] = x;
  }
  long long sum(int x) { return sm[root(x)]; }
  void snapshot() { history.clear(); }
  void rollback() {
    while (history.size()) {
      d[history.back().first] = history.back().second;
      history.pop_back();
    }
    while (smHis.size()) {
      sm[smHis.back().first] = smHis.back().second;
      smHis.pop_back();
    }
  }
};
struct Edge {
  int a, b;
  long long c;
  int id;
  Edge(int a, int b, long long c, int id) : a(a), b(b), c(c), id(id) {}
  bool operator<(const Edge& rhs) const { return c < rhs.c; }
};
vector<Edge> es;
int nn;
vector<long long> ss;
int SQRT = 318;
UF cpy[350];
void init() {
  UF uf(nn, ss);
  for (int i = 0; i <= es.size(); i++) {
    if (i % SQRT == 0) {
      uf.snapshot();
      cpy[i / SQRT] = uf;
    }
    if (i < es.size()) uf.unite(es[i].a, es[i].b);
  }
}
long long build(int until, int id) {
  UF& uf = cpy[until / SQRT];
  for (int i = until / SQRT * SQRT; i < until; i++) {
    uf.unite(es[i].a, es[i].b);
  }
  long long ans = uf.sum(id);
  uf.rollback();
  return ans;
}
void solve(long long N, long long M, std::vector<long long> X,
           std::vector<long long> A, std::vector<long long> B,
           std::vector<long long> Y) {
  for (int i = 0; i < A.size(); i++) {
    A[i]--, B[i]--;
    es.emplace_back(A[i], B[i], Y[i], i);
  }
  sort(es.begin(), es.end());
  nn = N;
  ss = X;
  init();
  int c = 0;
  for (int i = es.size() - 1; i >= 0; i--) {
    int a = es[i].a;
    int b = es[i].b;
    if (build(i + 1, a) < es[i].c) {
      c++;
    } else {
      for (int x = 0; x < 350; x++)
        if (cpy[x].d.size()) {
          cpy[x].unite(a, b);
          cpy[x].snapshot();
        }
    }
  }
  cout << c << endl;
}
int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> X(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &X[i]);
  }
  std::vector<long long> A(M);
  std::vector<long long> B(M);
  std::vector<long long> Y(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &A[i]);
    scanf("%lld", &B[i]);
    scanf("%lld", &Y[i]);
  }
  solve(N, M, std::move(X), std::move(A), std::move(B), std::move(Y));
  return 0;
}
