#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ull = uint64_t;
constexpr ll INF = 1000000000;
class UFtree {
  class UFnode {
   public:
    UFnode *p;
    int rank{0};
    ll max_edge;
    ll weight;
    explicit UFnode() : p{nullptr}, max_edge{0}, weight{0} {}
    explicit UFnode(UFnode *pa) : p{pa}, max_edge{0} {}
  };
  std::vector<UFnode> nodes;
  UFnode *parent(UFnode *x) {
    x->rank = 0;
    if (x->p == nullptr) {
      return x;
    }
    x->p = parent(x->p);
    x->p->max_edge = max(x->p->max_edge, x->max_edge);
    return x->p;
  }

 public:
  explicit UFtree(std::vector<UFnode>::size_type n) : nodes{n} {};
  bool same(int a, int b) {
    return this->parent(&nodes[a]) == this->parent(&nodes[b]);
  }
  void join(int a, int b, ll Y) {
    auto ap = this->parent(&nodes[a]);
    auto bp = this->parent(&nodes[b]);
    auto max_edge = max(ap->max_edge, bp->max_edge);
    max_edge = max(max_edge, Y);
    ap->max_edge = max_edge;
    bp->max_edge = max_edge;
    if (ap == bp) return;
    if (ap->rank < bp->rank) {
      ap->p = bp;
      return;
    }
    if (ap->rank == bp->rank) bp->rank += 1;
    bp->p = ap;
  }
  void set_empty() {
    for (int i = 0; i < nodes.size(); ++i) {
      nodes[i].p = nullptr;
      nodes[i].max_edge = 0;
    }
  }
  void set_weight(int i, ll w) { nodes[i].weight = w; }
  bool solve(const vector<ll> &X) {
    map<UFnode *, ll> p_sum;
    for (int i = 0; i < nodes.size(); ++i) {
      p_sum[parent(&nodes[i])] += X[i];
    }
    for (auto &&oo : p_sum) {
      if (oo.first->max_edge > oo.second) {
        return false;
      }
    }
    return true;
  }
};
void solve(istream &cin) {
  ll N;
  if (!(cin >> N)) {
    return;
  }
  ll M;
  cin >> M;
  vector<ll> X;
  UFtree uft(N);
  for (int i = 0; i < N; ++i) {
    ll tmp;
    cin >> tmp;
    X.push_back(tmp);
    uft.set_weight(i, tmp);
  }
  vector<ll> A, B, Y;
  vector<pair<ll, ll>> pr;
  for (int j = 0; j < M; ++j) {
    ll a, b, y;
    cin >> a >> b >> y;
    a--;
    b--;
    A.push_back(a);
    B.push_back(b);
    Y.push_back(y);
    pr.emplace_back(y, j);
  }
  sort(pr.begin(), pr.end());
  auto can = [&](ll m) {
    uft.set_empty();
    if (m < 0) return false;
    ll end = M - m;
    for (int i = 0; i < end; ++i) {
      ll t = pr[i].second;
      uft.join(A[t], B[t], Y[t]);
    }
    return uft.solve(X);
  };
  ll ok = M;
  ll ng = -1;
  while (abs(ng - ok) > 1) {
    ll mid = (ok + ng) / 2;
    if (can(mid)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  cout << ok << endl;
}
int main(int argc, char *argv[]) {
  string FileName("E"), Modifier("MEPH_");
  string ExecutionName = Modifier + FileName;
  string sub(argv[0]);
  if (sub.size() > ExecutionName.size())
    sub = sub.substr(sub.size() - ExecutionName.size(), ExecutionName.size());
  cout << setprecision(16) << scientific;
  if (sub != ExecutionName) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (cin) {
      solve(cin);
    }
  } else {
    cerr << sub << " test" << endl;
    string inFile = FileName + ".txt";
    auto fs = fstream(inFile, fstream::in);
    while (fs) {
      solve(fs);
    }
  }
}
