#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
struct UnionFindTree {
  int size;
  std::vector<int> parent;
  std::vector<int64> x;
  UnionFindTree() = default;
  UnionFindTree(int size) : size(size), parent(size, -1) {}
  UnionFindTree(vector<int64>& x)
      : size(x.size()), parent(x.size(), -1), x(x) {}
  int Size() const { return size; }
  int Size(int e) { return -parent[Root(e)]; }
  bool Same(int e1, int e2) { return Root(e1) == Root(e2); }
  void Unite(int e1, int e2) {
    if ((e1 = Root(e1)) != (e2 = Root(e2))) {
      if (Size(e1) < Size(e2)) {
        std::swap(e1, e2);
      }
      parent[e1] += parent[e2];
      x[e1] += x[e2];
      parent[e2] = e1;
      size--;
    }
  }
  int64 Weight(int e) {
    e = Root(e);
    return x[e];
  }
  int Root(int e) {
    if (parent[e] < 0) return e;
    parent[e] = Root(parent[e]);
    return parent[e];
  }
};
struct Edge {
  using Weight = int64;
  int end1, end2;
  Weight weight;
  Edge() = default;
  Edge(int end1, int end2, Weight weight)
      : end1(end1), end2(end2), weight(weight) {}
  bool operator<(const Edge& e) const { return weight < e.weight; }
};
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int64> x(n);
  for (auto i = decltype(n)(); (i) < (n); (i)++) {
    cin >> x[i];
  }
  vector<Edge> edges;
  for (auto i = decltype(m)(); (i) < (m); (i)++) {
    int a, b, y;
    cin >> a >> b >> y;
    a--;
    b--;
    edges.emplace_back(a, b, y);
  }
  sort(begin(edges), end(edges));
  static UnionFindTree union_find(x);
  vector<Edge> bad_edges;
  int ans = m;
  for (auto i = decltype(m)(); (i) < (m); (i)++) {
    Edge& e = edges[i];
    union_find.Unite(e.end1, e.end2);
    if (e.weight > union_find.Weight(e.end1)) {
      bad_edges.push_back(e);
    }
    while (!bad_edges.empty()) {
      Edge bad_e = bad_edges.back();
      if (bad_e.weight > union_find.Weight(bad_e.end1)) {
        break;
      }
      bad_edges.pop_back();
    }
    if (bad_edges.empty()) ans = m - i - 1;
  }
  cout << ans << endl;
  return 0;
}
